首页 > 解决方案 > vue/cli3.0时使用DllPlugin和DllReferencePlugin错误

问题描述

我想拉出依赖包,但我遇到了问题。使用 vue/cli3.0

在线链接是https://github.com/Sayid1/dll-test

主要代码

vue.config.js

var bundleConfig = require('./bundle-config.json')

module.exports = {
  configureWebpack: {
    plugins: [
      new webpack.DllReferencePlugin({
        manifest: require('./dll/manifest.json')
      }),
      new HtmlWebpackPlugin({
        inject: true,
        template: './public/index.html',
        filename: 'index.html',
        vendorJsName: bundleConfig.vender.js,
      })
    ]
  }
}

webpack.config.dll.js

const AssetsPlugin = require('assets-webpack-plugin')

module.exports = {
  entry: {
    vender: ['vue/dist/vue.runtime.common.js']
  },
  output: {
    path: path.join(__dirname, 'dll'),
    filename: 'dll.[name]_[hash].js',
    library: '[name]_[hash]'
  },
  plugins: [
    new webpack.DllPlugin({
      name: '[name]_[hash]',
      path: path.join(__dirname, 'dll', 'manifest.json')
    }),
    new AssetsPlugin({
      filename: 'bundle-config.json',
      path: './'
    })
  ]
}

我运行这个脚本:

webpack -p --progress --config webpack.config.dll.js

然后启动服务器

发生了错误。

Uncaught SyntaxError: Unexpected token <

Uncaught ReferenceError: vender_87f3be8acd6aadd91537 is not defined
    at eval (eval at dll-reference vender_87f3be8acd6aadd91537 (app.js:2106), <anonymous>:1:18)
    at Object.dll-reference vender_87f3be8acd6aadd91537 (app.js:2106)
    at __webpack_require__ (app.js:724)
    at fn (app.js:101)
    at eval (global.js from dll-reference vender_87f3be8acd6aadd91537?478a:1)
    at Object../node_modules/webpack/buildin/global.js (app.js:1896)
    at __webpack_require__ (app.js:724)
    at fn (app.js:101)
    at eval (punycode.js:521)
    at Object../node_modules/node-libs-browser/node_modules/punycode/punycode.js (app.js:1685)

标签: vue.jswebpack-4vue-cli-3dllplugin

解决方案


推荐阅读