webpack-hot-middleware不是很热门的替代品

时间:2016-03-21 00:51:15

标签: webpack

这是我的服务器代码:

if (process.env.NODE_ENV === 'development') {
        // Enable logger (morgan)
        app.use(morgan('dev'));

        // Disable views cache
        app.set('view cache', false);

        var webpack = require('webpack');
        var webpackDevMiddleware = require('webpack-dev-middleware');
        var webpackHotMiddleware = require('webpack-hot-middleware');

        var webpackConfig = require('../client/webpack.config');
        var compiler = webpack(webpackConfig);

        app.use(webpackDevMiddleware(compiler, { noInfo: true, publicPath: webpackConfig.output.publicPath }));
        app.use(webpackHotMiddleware(compiler));

    }

这是我的webpack.config:

module.exports = {
  entry: {
    main: [
        'webpack-hot-middleware/client',
        './client/src/main'
    ]
  },
  output: {
    path: path.join(__dirname, 'client/build'),
    filename: 'bundle.js',
    publicPath: '/build/'
  },
  plugins: [
    new AureliaWebpackPlugin(),
    new webpack.optimize.OccurenceOrderPlugin(),
    new webpack.HotModuleReplacementPlugin(),
    new webpack.NoErrorsPlugin()
  ],
  module: {
    loaders: [
      { test: /\.js$/, loader: 'babel', exclude: /node_modules/, query: {stage: 0} },
      { test: /\.css?$/, loader: 'style!css' },
      { test: /\.html$/, loader: 'raw' },
      { test: /\.(png|gif|jpg)$/, loader: 'url-loader?limit=8192' },
      { test: /\.woff2(\?v=[0-9]\.[0-9]\.[0-9])?$/, loader: 'url-loader?limit=10000&minetype=application/font-woff2' },
      { test: /\.woff(\?v=[0-9]\.[0-9]\.[0-9])?$/, loader: 'url-loader?limit=10000&minetype=application/font-woff' },
      { test: /\.(ttf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/, loader: 'file-loader' }
    ]
  }
};

每次更改源文件时,webpack都不会重建。但是,浏览器中没有热替换/重新加载...我错过了什么吗?我以为我非常仔细地遵循了指示。

提前致谢。

2 个答案:

答案 0 :(得分:5)

当我向webpack-hot-middleware添加一些参数以启用HMR,并在条目中向webpack-hot-middleware / client查询参数时,我的问题已成功解决,如下所示:

//#server.js  add parameters to Enables HMR
    app
    .use(webpackHotMiddleware(compiler, {
       'log': false, 
       'path': '/__webpack_hmr', 
       'heartbeat': 10 * 1000
    }))


//# webpack.config.js:
       entry: {
         main: [
            'webpack-hot-middleware/client?path=/__webpack_hmr&timeout=20000&reload=true',
            './client/src/main'
              ]

答案 1 :(得分:1)

所以我的问题实际上已在文档中介绍过了。我正在使用webpack-hot-middleware上游的压缩模块,并且没有更新压缩。

看到此问题: https://github.com/glenjamin/webpack-hot-middleware/issues/10

基本上,如果您使用压缩,请确保升级到^ 1.6。我升级了1.2 - > 1.6.1而且我现在正在热重装。