【问题标题】:Express static server returns html for bundle.js for react build from webpackExpress 静态服务器返回 bundle.js 的 html 以从 webpack 进行反应构建
【发布时间】:2020-12-02 11:28:58
【问题描述】:

我正在尝试使用 express.static 中间件为生产构建反应应用程序提供服务,但总是得到一个空白页面。经过调查,我注意到由于某种原因,bundle.js 内容实际上是 html。中间件和配置如下。

app.use(express.static(path.join(__dirname, 'client/dist')));
app.get('*', (req, res) =>
  res.sendFile(path.join(__dirname, '/client/dist/index.html'))
);

【问题讨论】:

  • 你能把你的 webpack 配置也放上来吗?
  • @AravindaMeewalaarachchi,我已经设法解决了,非常感谢您的回复。

标签: node.js reactjs express webpack


【解决方案1】:

这有点奇怪,将 js 和 css 拆分到子目录似乎已经成功了。

初始dist结构,

/dist
index.html
bundle.js
main.css

按如下方式拆分文件

/dist
index.html
 /js
  bundle.js
 /css
  main.css

【讨论】:

    猜你喜欢
    • 2020-03-08
    • 1970-01-01
    • 1970-01-01
    • 2019-03-10
    • 1970-01-01
    • 2016-06-26
    • 1970-01-01
    • 2017-01-06
    • 2018-03-17
    相关资源
    最近更新 更多