【问题标题】:Webpack not reloading at all even on page refresh即使在页面刷新时,Webpack 也根本不会重新加载
【发布时间】:2017-11-28 16:42:07
【问题描述】:

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

的主页
<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.

【问题讨论】:

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


    【解决方案1】:

    添加

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

    在 package.json 中的脚本中并使用 npm start 运行您的应用,它应该会自动刷新。ue,

    使用安装依赖项

    npm install webpack-dev-server --hot
    

    看看你的错误

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

    【讨论】:

      猜你喜欢
      • 2012-12-13
      • 2018-08-20
      • 1970-01-01
      • 2013-01-31
      • 1970-01-01
      • 2010-12-24
      • 2016-06-26
      • 1970-01-01
      • 2019-07-29
      相关资源
      最近更新 更多