There are three possible reasons for this error
- The context context is inconsistent
- Library and name are inconsistent
- The generated DLL file is not added to the HTML file
dll.config.js
module.exports = {
mode:"production",
output: {
path:path.resolve(__dirname, '../dist'),
filename: '[name].dll.js',
Library: dllname, // and dllplugin are required here option.name agreement
},
entry: {
"lib": vendors,
},
plugins: [
new webpack.DllPlugin({
path:path.resolve(__dirname,'../dist/manifest.json'),
name: dllName,
context: __ Dirname, // context is required
}),
new CleanWebpackPlugin([`./dist/*.dll.js`,`./dist/*.json`], { root: path.resolve(__dirname, "../") }),
]
}
webpack.config.js
new webpack.DllReferencePlugin({
context: __ Dirname, // this context corresponds to dllplugin
manifest: require('../dist/manifest.json')}
),
new AddAssetHtmlPlugin(
[
{
filepath: "./dist/*. dll.js ", // add the generated DLL file to index.html in
},
]
),