webpack 热更新 HMR(Hot Module Replacement)
热更新的原理
热更新使用
devServer: {
contentBase: './dist',
port: '7008',
inline: true,
host: '0.0.0.0',
disableHostCheck: true,//不使用白名单的原因是多人开发,每个人都需要绑定Host不方便,因此关闭Host检查
hot: true, //开启热更新
},
plugins: [
new MiniCssExtractPlugin({
filename: "css/[name].css",
}),
new HtmlWebpackPlugin({
title: 'Output Management'
}),
new webpack.HotModuleReplacementPlugin() //开启热更新
],
// 在webpack 入口js底部加上以下代码
if (module.hot) {
module.hot.accept();
}
before: (app) => {
app.use('*', (req, res, next) => {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Methods", "POST,GET");
res.header("Access-Control-Allow-Headers", "Origin,Accept,Content-Type,Content-Length, Authorization, Accept,X-Requested-With");
next();
});
}
热更新的优化方式
最后更新于