模块热更新是webpack的一个功能,他可以使代码修改过后不用刷新就可以更新,是高级版的 自动刷新浏览器
devServer中通过hot属性可以控制模块的热替换
通过配置文件
const webpack = require(‘webpack ‘);
const path = require(‘path’);
let env = process, env. N0DE_ENV = "development" ? "development" : "production";
const config = {
mode: env,
devServer: {
hot:true
}
}
plugins:[
new webpack. HotModuleReplacementPlugin() , 〃热加载插件
],
module.exports = config;
通过命令行
"scripts": {
"test": "echo "Error: no test specifiedX" && exit 1",
"start": "NODE_ENV=deve1opment webpack-dev-server—config webpack. develop, config.js —hot", },

Was this helpful?

0 / 0

发表回复 0

Your email address will not be published.