G
G
Gibi2015-11-28 01:07:49
JavaScript
Gibi, 2015-11-28 01:07:49

How to enable HMR support in webpack?

Hello. I decided to start using webpack for:
1) generating initial data for the public (minification, sprites, etc.)
2) using hot module replacement.
3), etc.
There were difficulties when using HMR, the page is completely reloaded.
HMR] Cannot apply update. Need to do a full reload!
[HMR] Error: Aborted because 76 is not accepted
...
Uncaught RangeError: Maximum call stack size
exceeded

webpackHotUpdate(0,{

/***/ 76:
/***/ function(module, exports) {

  console.log('test');

/***/ }

})
//# sourceMappingURL=0.a2c058c04b843eab955f.hot-update.js.map

How is the problem solved?
What I noticed
If you visit the address:
localhost:8080/webpack-dev-server - the page does not reload, the log remains in the console, in fact, I saw an error there.
localhost:8080 - the page is reloaded.
UPD.
config.js
var webpack = require("webpack"),
  ExtractTextPlugin = require("extract-text-webpack-plugin"),
  PathRewriterPlugin = require('webpack-path-rewriter');

module.exports = {
  devtool: 'source-map',

  entry: {
    app: [
        'webpack-dev-server/client?http://localhost:8080',
        'webpack/hot/dev-server',
        './src/bundle.js'
      ]
  },

  output: {
    path: '/public/',
    filename: '[name].js'
  },

  module: {
    loaders: [{
      test: /\.js$/,
      exclude: /node_modules/,
      loader: "babel"
    }, {
      test: /\.scss$/,
      loader: ExtractTextPlugin.extract("style", "css!sass!autoprefixer")
    }, {
      test: /\.(png|jpg)$/,
      loader: "url?limit=3000&name=[name].[ext]?[hash]"
    }, {
      test: /.jade$/,
      loader: PathRewriterPlugin.rewriteAndEmit({
        name: 'index.html',
        loader: 'jade-html?' + JSON.stringify({
          pretty: true
        }),
        includeHash: true
      })
    }]
  },

  plugins: [
    new webpack.HotModuleReplacementPlugin(),
    new ExtractTextPlugin('[name].css', {
      allChunks: true,
      disable: process.env.NODE_ENV == 'development'
    }),
    new PathRewriterPlugin(),
    new webpack.NoErrorsPlugin()
  ]
};

bundle.js
// Js
require('./js/index.js');

// Jade
require('./jade/index.jade');

index.js
console.log('test');
index.jade
doctype html
html
  head
    meta(charset='utf-8')
    title(v-text='title')
    meta(name='viewport', content='width=device-width, initial-scale=1, user-scalable=no')
    link(href='', media='all', rel='stylesheet')
    script(src='')
  body
    .div Тест

There is a desire to set up environments for development devs with HMR work, and be able to generate files for production.
When changing js, css, the page is reloaded. When changing jade, there are no reactions at all.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ilya Kantor, 2015-12-02
@Gibi

How do you run webpack? By chance, don't you add `--hot`? The error looks like two HotModuleReplacement plugins.
Here, look at the issue about HMR, learn.javascript.ru/webpack-screencast , maybe it will remove questions?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question