方式1,通過 webpackDevMiddleware 和 webpackHotMiddleware:
server.js:
const webpackDevMiddleware = require("webpack-dev-middleware");
const webpackHotMiddleware = require("webpack-hot-middleware");
const compiler = webpack(config);
const app = express();
// auto refresh
app.use(webpackDevMiddleware(compiler, {
publicPath: '/',
}));
app.use(webpackHotMiddleware(compiler));
方式2,通過WebpackDevServer:
Webpack.config.js:
var server = new webpackDevServer(compiler, {
hot: true
...
});
server.listen(8000);