Webpack甚至在页面刷新时都没有重新加载

时间:2017-06-25 19:03:30

标签: reactjs webpack webpack-dev-server webpack-2

所以发生的事情是我有一个只有

的主页
<h1>Home</h1>
<p>This is the home page!</p>

例如,如果我将Home更改为test,则在重新启动webpack之前没有任何反应(关闭连接,重新运行webpack -d)。因此,热重装不仅不起作用,也不会重新加载。我不知道它是什么,我以为我已经正确地遵循了所有的教程。

我的webpack配置:

const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const webpack = require('webpack');

module.exports = {
  entry: [
    'webpack-hot-middleware/client',
    './client/src/index.js'
  ],
  output: {
    path: path.join(__dirname, 'server', 'static', 'js'),
    filename: 'bundle.js'
  },
  resolve: {
    extensions: ['.js', '.jsx', '.json']
  },
  devServer: {
    historyApiFallback: true
  },
  module: {
    rules: [
      {
        test: /\.jsx?$/,
        exclude: /node_modules/,
        use: [ 'react-hot-loader/webpack', 'babel-loader' ],
      }
    ]
  },
  plugins: [
    new HtmlWebpackPlugin({
      inject: 'body',
      filename: 'index.html'
    }),
    new webpack.optimize.OccurrenceOrderPlugin(),
    new webpack.HotModuleReplacementPlugin(),
    new webpack.NoEmitOnErrorsPlugin(),
    new webpack.DefinePlugin({
      'process.env.NODE_ENV': JSON.stringify('development')
    })
  ]
};

我正在运行webpack -d

这就是我所假设的所有重要包裹我也在使用:

"babel-preset-node6": "^11.0.0",
"babel-preset-react-hmre": "^1.1.1",
"babel-preset-stage-0": "^6.24.1",
"react-dom": "^15.6.1",
"react-hot-loader": "^3.0.0-beta.7",
"react-redux": "^5.0.5",
"react-router-dom": "^4.1.1",
"react-router-redux": "^4.0.8",
"react-scripts": "^1.0.7",
"react-slick": "^0.14.11",
"redux": "^3.7.0",
"redux-logger": "^3.0.6",
"redux-mock-store": "1.0.2",
"redux-thunk": "^2.2.0",
"sequelize": "^4.1.0",
"sequelize-cli": "^2.7.0",
"webpack": "^3.0.0",
"webpack-dev-server": "^2.4.5",
"webpack-hot-middleware": "^2.18.0",

此外,我发现另一个错误,我认为与整体重新加载无关,但与热重新加载有关,如果有人可以提供一些建议会有所帮助:

EventSource's response has a MIME type ("text/html") that is not "text/event-stream". Aborting the connection.

1 个答案:

答案 0 :(得分:0)

添加

"start": "webpack-dev-server --hot"

在package.json的脚本中并使用npm start运行你的应用程序,它应该自动刷新。\ n,

使用

安装依赖项
npm install webpack-dev-server --hot

看看你的错误

https://github.com/glenjamin/webpack-hot-middleware/issues/26