Webpack Hot Middleware安装和使用
一、首先, 安装 npm 模块
npm install --save-dev webpack-hot-middleware
二、 然后, 在webpack.config.js中配置
1、将下面的plugins添加到webpack的配置中:
// webpack.config.js
plugins: [
// OccurenceOrderPlugin is needed for webpack 1.x only
new webpack.optimize.OccurenceOrderPlugin(),
new webpack.HotModuleReplacementPlugin(),
new webpack.NoErrorsPlugin()
]
2、将’webpack-hot-middleware/client’ 添加到webpack配置文件的入口配置数组中. 连接到服务器时收到通知束重建,然后相应地更新你的客户包。
// webpack.config.js
var webpack = require('webpack');
var webpackConfig = require('./webpack.config');
var compiler = webpack(webpackConfig);
app.use(require("webpack-dev-middleware")(compiler, {
noInfo: true, publicPath: webpackConfig.output.publicPath
}));
3、将webpack-hot-middleware 附加到相同的编译器实例
app.use(require("webpack-hot-middleware")(compiler));