- 修改 webpack 的配置:
entry: [‘webpack-hot-middleware/client?noInfo=true&reload=true’, ‘./src/main.js’],
plugins: [new webpack.HotModuleReplacementPlugin()] -
服务器代码的实现:
const express = require(‘express’)
const webpack = require(‘webpack’)
const config = require(‘./webpack.config.js’)
const webpackDevMiddleware = require(‘webpack-dev-middleware’)
const webpackHotMiddleware = require(‘webpack-hot-middleware’)const app = new express()
const compiler = webpack(config)app.use(webpackDevMiddleware(compiler, {
publicPath: config.output.publicPath
}))
app.use(webpackHotMiddleware(compiler, {log: (info) => console.log(info), heartbeat: 1000
}))
app.listen(8080, () => {
console.log('server started!')
})