要解决部署后Webpack代码块未重新加载的问题,可以尝试以下解决方法:
// webpack.config.js
module.exports = {
output: {
publicPath: '/'
}
};
// webpack.config.js
const webpack = require('webpack');
module.exports = {
devServer: {
hot: true
},
plugins: [
new webpack.HotModuleReplacementPlugin()
]
};
在入口文件中添加热模块替换的代码:
// index.js
if (module.hot) {
module.hot.accept();
}
// webpack.config.js
const webpack = require('webpack');
const { HashedModuleIdsPlugin, ManifestPlugin } = require('webpack');
module.exports = {
plugins: [
new HashedModuleIdsPlugin(),
new ManifestPlugin()
]
};
然后在HTML模板中引用生成的manifest文件,并根据文件名的变化来更新引用的文件路径。
以上是一些常见的解决方法,具体的解决方法可能会根据项目的具体情况而有所不同。