使用最新的UglifyJsPlugin for Webpack编译的应用程序显示“webpackJsonp未定义”

时间:2017-12-20 07:36:24

标签: javascript webpack vue.js uglifyjs

我正在使用官方Vue Webpack template

Webpack附带的UglifyJs无法编译ES6。所以我更改了Webpack插件的standalone version

// webpack.prod.conf.js

var UglifyJsPlugin = require('uglifyjs-webpack-plugin')

new UglifyJsPlugin({
  uglifyOptions: {
    ie8: false,
    ecma: 8,
    parse: {},
    mangle: {
      properties: {
        // mangle property options
      }
    },
    output: {
      comments: false,
      beautify: false,
    },
    compress: {},
    warnings: false
  }
}),

当我执行npm run build时,应用会正确编译。但是,当我执行npm start并访问localhost:3000时,我收到此错误:

vendor.dc780f28ecc8d64eb53a.js:1 Uncaught ReferenceError: webpackJsonp is not defined
    at vendor.dc780f28ecc8d64eb53a.js:1
(anonymous) @ vendor.dc780f28ecc8d64eb53a.js:1
app.470f1cb076c387c73cdc.js:1 Uncaught ReferenceError: webpackJsonp is not defined
    at app.470f1cb076c387c73cdc.js:1
(anonymous) @ app.470f1cb076c387c73cdc.js:1
babel-polyfill.fc14d31ef0450ee23f4b.js:1 Uncaught ReferenceError: webpackJsonp is not defined
    at babel-polyfill.fc14d31ef0450ee23f4b.js:1

可能是什么原因?

1 个答案:

答案 0 :(得分:1)

尝试使用:

new webpack.optimize.CommonsChunkPlugin('vendor', 'vendor.js', Infinity)