简体   繁体   English

Webpack的UglifyJsPlugin无法编译ES6软件包

[英]Webpack's UglifyJsPlugin not able to compile ES6 packages

I have this in my Webpack setup: 我的Webpack设置中有这个:

// webpack.prod.conf.js
new webpack.optimize.UglifyJsPlugin({
  compress: {
    warnings: false,
    drop_console: shouldDropConsole
  },
  sourceMap: true
}),

// .babelrc
"presets": [
  ["stage-2"],
  ["es2015",  {"modules": false}]
],

When I do npm run build I get the following error: 当我执行npm run build ,出现以下错误:

ERROR in static/js/vendor.8b608f0ab832a371f4a5.js from UglifyJs Unexpected token: name (finish) [./node_modules/pica/lib/mathlib.js:35,0][static/js/vendor.8b608f0ab832a371f4a5.js:38950,6] 来自UglifyJs的static / js / vendor.8b608f0ab832a371f4a5.js中的错误意外令牌:名称(完成)[./node_modules/pica/lib/mathlib.js:35,0][static/js/vendor.8b608f0ab832a371f4a5.js:38950, 6]

So UglifyJS doesn't recognize the ES6 code there: let . 因此,UglifyJS在此处无法识别ES6代码: let

How to solve this? 如何解决呢? Is there any workaround? 有什么解决方法吗? (I'm using Webpack 3.6.0). (我正在使用Webpack 3.6.0)。

I found the solution (how to transpile ES6 to ES5 for node modules in a Webpack setup): 我找到了解决方案(如何在Webpack设置中为节点模块转换ES6到ES5):

  {
    test: /\.js$/,
    loader: 'babel-loader',
    include: [
     resolve('src'),
     resolve('test'),
     resolve('node_modules/pica'),
     resolve('node_modules/countries-list')
  ],

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM