webpack DllPlugin xxx is not defined解决办法

 更新时间:2019年12月13日 09:17:04   作者:ZoeLee  
这篇文章主要介绍了webpack DllPlugin xxx is not defined解决办法,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧

造成这个错误主要有3个可能的原因:

  • context上下文不一致
  • library和name 不一致
  • 生成的dll文件没加入到html文件中

dll.config.js

module.exports = {
  mode:"production",
  output: {
    path:path.resolve(__dirname, '../dist'),
    filename: '[name].dll.js',
    library: dllName, //这里需要和DllPlugin option.name 一致
  },
  entry: {
    "lib": vendors,
  },
  plugins: [
    new webpack.DllPlugin({
      path:path.resolve(__dirname,'../dist/manifest.json'),
      name: dllName,
      context: __dirname, //上下文必填
    }),
    new CleanWebpackPlugin([`./dist/*.dll.js`,`./dist/*.json`], { root: path.resolve(__dirname, "../") }),
  ]
 }

webpack.config.js   

 new webpack.DllReferencePlugin({
   context: __dirname, //这个上下文对应DllPlugin
   manifest: require('../dist/manifest.json')}
   ),
   new AddAssetHtmlPlugin( 
    [
      {
        filepath: "./dist/*.dll.js", //将生成的dll文件加入到index.html中
      },
    ]
  ),

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。

相关文章

最新评论