0

This is the relevant code (I'm using Vue.js' Webpack official template):

.babelrc:

"presets": [
  "babel-preset-es2015",
  "babel-preset-stage-2",
]

webpack.prod.config.js

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

This is the error I get when I do npm run build:

ERROR in static/js/vendor.a6271913414e87e123c2.js from UglifyJs Unexpected token: name (_months) [./node_modules/calendar-js/index.js:56,0][static/js/vendor.a6271913414e87e123c2.js:90602,6]

This is the offending line:

let _months = MONTHS;

(If I replace all the let's to vars the project is built without problems. And the const's don't seem to bother Webpack/UglifyJS.)

Do I need to configure something so that Webpack/UglifyJS build node modules containing let's? (The let's in my actual project don't give me problems.)

4

1 回答 1

1

这可能是因为您可能使用的node是不支持 es6 语法的旧版本。

let, const, 箭头函数等是 es6 语法的一部分。要了解更多信息,请点击此链接http://es6-features.org/

node您的其他项目可能需要旧版本的,因此请安装 nvm。NVM 是一个节点版本管理器,可以帮助您轻松地在节点版本之间切换。按照文档和安装过程的链接https://github.com/creationix/nvm

Node v6+ 支持 ES6 语法尝试升级到那个。

更新

在此答案的评论中,已确认这不是版本问题,并通过遵循此 GitHub 问题线程https://github.com/joeeames/WebpackFundamentalsCourse/issues/3得到解决。

和平!

于 2017-12-20T06:29:25.143 回答