webpack configuration:
entry:{
"index":["webpack-hot-middleware/client?path=/__webpack_hmr&timeout=10000&reload=true",path.resolve("assets/view/index/entry.js")],
"sub":["webpack-hot-middleware/client?path=/__webpack_hmr&timeout=10000&reload=true",path.resolve("assets/view/sub/entry.js")]
},
....
plugins: [
new webpack.HotModuleReplacementPlugin(),
new webpack.NoEmitOnErrorsPlugin()
]
< hr >
Code in express
if (process.env.DEV_MODE === "dev") {
let webpack = require("webpack");
let webpackDevMiddleWare = require("webpack-dev-middleware");
let webpackHotMiddleWare = require("webpack-hot-middleware");
let webpackConfig = require("./webpack.dev.config");
let complier = webpack(webpackConfig);
app.use(webpackDevMiddleWare(complier, {
stats: {
assets: true,
children: false,
modules: false,
colors: true
}
}));
app.use(webpackHotMiddleWare(complier));
}
The service is up, and it can also be packaged through webpack-dev-middleware
, and the HRM is also valid. If you change the css,js, you will automatically refresh it, but the html code will be changed and the page will not be refreshed.
how do you solve this problem?