Webpack Dev Server (webpack-dev-server) Hot Module Replacement (HMR) Not Working

前端 未结 6 2763
执笔经年
执笔经年 2021-02-19 22:48

I have gone through many answers on StackOverflow & on GitHub issues as well but, I am still stuck in Hot Module Replacement in Webpack. I am using npm start to

6条回答
  •  走了就别回头了
    2021-02-19 23:19

    Your webpack config is off. Take a look at react-transform-boilerplate for a correct setup.

    webpack.config.js

    var path = require('path');
    var webpack = require('webpack');
    
    module.exports = {
      // or devtool: 'eval' to debug issues with compiled output:
      devtool: 'cheap-module-eval-source-map',
      entry: [
        // necessary for hot reloading with IE:
        'eventsource-polyfill',
        // listen to code updates emitted by hot middleware:
        'webpack-hot-middleware/client',
        // your code:
        './src/index'
      ],
      output: {
        path: path.join(__dirname, 'dist'),
        filename: 'bundle.js',
        publicPath: '/dist/'
      },
      plugins: [
        new webpack.HotModuleReplacementPlugin(),
        new webpack.NoErrorsPlugin()
      ],
      module: {
        loaders: [{
          test: /\.js$/,
          loaders: ['babel'],
          include: path.join(__dirname, 'src')
        }]
      }
    };
    

    .babelrc

    {
      "presets": ["react", "es2015"],
      "env": {
        "development": {
          "presets": ["react-hmre"]
        }
      }
    }
    

提交回复
热议问题