some es6 features are not understood by grunt uglify js?

被刻印的时光 ゝ 提交于 2019-11-28 11:58:18

Officially there's no tool that minifies ES6 yet (Other tools like Google Closure compiler supports ES6 but it transpile it into "traditional js" and then it's minified).

Although not all the es6 features are supported in UglifyJs, the Harmony branch of UglifyJS2 seems to support arrow functions and other features.

You can read the discussion about it in the issue of github here. It seems there's not another option to wait (or create your own ES6 minifier).

Update

Now you have 2 options to minify ES6:

You can use the harmony branch of grunt-contrib-uglify.

npm install git://github.com/gruntjs/grunt-contrib-uglify.git#harmony --save-dev

works perfectly with es6. No additional settings for grunt are required.

If the resulting code does not need to use ES6 syntax, it is also possible to transpile ES6 to ES5, before uglifying your code. This can for example be done with the Grunt task grunt-es6-transpiler.

I just updated to uglify-js@2.8.29 and it worked.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!