我遇到了一个奇怪的问题,我试图使用 DllPlugin、DllReferencePlugin 和 AddAssetHtmlPlugin 优化我的 webpack 包构建时间,当我运行“npm run build”时它运行良好。生成了名为 vendor.dll.js 的文件并注入到 index.html 中。但是,当我运行“npm run local”时,浏览器中抛出了上述错误。谁知道怎么修它?任何建议将不胜感激。
我的部分代码如下(对不起,我不能在这里发布我所有的代码)
webpack.dll.config.js
module.exports = {
vendor: [
'core-js',
'lodash',
'axios',
'react',
'react-dom',
'redux',
]
},
output:{
path:path.join(__dirname,'/../build/'),
filename:'[name].dll.js',
library:'[name]_library'
},
plugins:[
new webpack.DllPlugin({
path:path.join(__dirname,'./../build/','[name]-manifest.json'),
name:'[name]_library',
context:path.join(__dirname, './../build/')
}),
]
}
webpack.config.default.js
module.exports = () => {
//...
webpack: (webpackConfig, webpack, env) => {
webpackConfig.plugins.push(
new HtmlWebpackPlugin({
template: path.resolve(__dirname, '../server/view/home.html'),// template html file
minify: {
removeComments: false
}
})
);
webpackConfig.plugins.push(
new webpack.DllReferencePlugin({
context:path.join(__dirname, '/../build/'),
manifest: require('../build/vendor-manifest.json')
})
);
webpackConfig.plugins = (webpackConfig.plugins || []).concat([
new AddAssetHtmlPlugin({
filepath:path.resolve(__dirname, '../build/vendor.dll.js'),
includesourcemap: false,
hash: true
}),
]);
}
}