javascript - Webpack - [HMR] Hot Module Replacement is disabled - Stack Overflow

I've looked around, but can't get any of the answers I've seen on stackoverflow to work.

I've looked around, but can't get any of the answers I've seen on stackoverflow to work.

I cannot use the mand line for webpack or the webpack dev-server; I am restricted to using the Node API.

Below is how I am using webpack.

webpack.config.js

module.exports = {
  entry: [
    'webpack-dev-server/client?http://localhost:3000',
    // i've also tried webpack/hot/dev-server here
    'webpack/hot/only-dev-server',
    path.join(__dirname, 'src', 'js', 'app.jsx')
  ],
  output: {
    path: path.join(__dirname, 'dist', 'js'),
    filename: 'script.js',
    publicPath: '/dist/'
  },
  module: {
    loaders: [{
      test: /\.(js|jsx)$/,
      loaders: ['react-hot', 'babel']
    }]
  },
  plugins: []
};

contained in a gulp task "start"

gulp.task('start', function (callback) {
  var config = Object.create(require('webpack.config.js'));
  config.plugins.push(new webpack.HotModuleReplacementPlugin());

  var devServer = new webpackDevServer(webpack(config), {
    stats: { colors: true },
    contentBase: path.resolve(__dirname, 'dist'),
    progress: true,
    inline: true,
    hot: true
  });
});

What I expect

When I run gulp start, I expect the webpack dev server to spin up, allowing me to hit localhost:3000/. This should load an index.html from my project's /dist/ folder. So far so good. I expect that when I make a change to a file (e.g., app.jsx), that the change would be present.

What is actually happening

I am getting the error "[HMR] Hot Module Replacement is disabled", with no further explanation.

Any help would be appreciated. I have been trying to get hot reloading working for a full day.

I've looked around, but can't get any of the answers I've seen on stackoverflow to work.

I cannot use the mand line for webpack or the webpack dev-server; I am restricted to using the Node API.

Below is how I am using webpack.

webpack.config.js

module.exports = {
  entry: [
    'webpack-dev-server/client?http://localhost:3000',
    // i've also tried webpack/hot/dev-server here
    'webpack/hot/only-dev-server',
    path.join(__dirname, 'src', 'js', 'app.jsx')
  ],
  output: {
    path: path.join(__dirname, 'dist', 'js'),
    filename: 'script.js',
    publicPath: '/dist/'
  },
  module: {
    loaders: [{
      test: /\.(js|jsx)$/,
      loaders: ['react-hot', 'babel']
    }]
  },
  plugins: []
};

contained in a gulp task "start"

gulp.task('start', function (callback) {
  var config = Object.create(require('webpack.config.js'));
  config.plugins.push(new webpack.HotModuleReplacementPlugin());

  var devServer = new webpackDevServer(webpack(config), {
    stats: { colors: true },
    contentBase: path.resolve(__dirname, 'dist'),
    progress: true,
    inline: true,
    hot: true
  });
});

What I expect

When I run gulp start, I expect the webpack dev server to spin up, allowing me to hit localhost:3000/. This should load an index.html from my project's /dist/ folder. So far so good. I expect that when I make a change to a file (e.g., app.jsx), that the change would be present.

What is actually happening

I am getting the error "[HMR] Hot Module Replacement is disabled", with no further explanation.

Any help would be appreciated. I have been trying to get hot reloading working for a full day.

Share Improve this question asked Sep 8, 2016 at 23:37 coolpic.jpg.execoolpic.jpg.exe 311 silver badge2 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 1

in your webpack.config.js on the plugins section try this,

plugins: [new webpack.HotModuleReplacementPlugin()]

I know you are pushing the plugin in your gulp task but you have to use --hot --inline on cli or on your npm script

Try to run webpack as webpack-dev-server --hot --inline in packge.json, somehow official docs is wrong now.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745670380a4639367.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信