I used grunt-uglify in my project and I'm working with es6. for some es6 features, such as fat arrow function, it's throwing an error. I think the uglify don't understant that syntax. so do i have a way to fix this issue. I mean can i use anything to make uglify understand all the es6 syntaxes?
相关问题
- Is there a limit to how many levels you can nest i
- How to toggle on Order in ReactJS
- How to toggle on Order in ReactJS
- void before promise syntax
- Keeping track of variable instances
You can use the
harmony
branch ofgrunt-contrib-uglify
.works perfectly with es6. No additional settings for grunt are required.
I just updated to uglify-js@2.8.29 and it worked.
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:
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.
A Grunt plugin ES6 parser, mangler/compressor and beautifier toolkit for ES6+ is now available:
https://github.com/adascal/grunt-terser
Great job, it just works as expected.
The
harmony
branch ofgrunt-contrib-uglify
is deprecated, it's not a sustainable solution.