问题
Hey guys I'm currently using uglify-gulp with babel to minify my js. And it works great with es2015 and es2016. But it breaks if I try to do es2017.
Does anyone know any workarounds to minify js that is using the new experimental features in es2017?
gulp.src('build/js/bundled/bundle.js')
.pipe(babel({
compact: false,
presets: ["es2017", "react"],
plugins: ["transform-decorators-legacy"],
}))
.pipe(uglify())
.pipe(gulp.dest('build/js/bundled'));
which generates this error
GulpUglifyError: unable to minify JavaScript
If I change es2017 to es2015/es2016 it will minify my bundles that don't have es2017 features just fine. But I want to be able to use those experimental features and be able to minify my code
回答1:
I think that Uglify can't parse some ES2015 features, so you need to transpile those down to ES5 (es2017
targets Node 5+).
With these webpack instructions, specifically the presets and plugins, you should be able to get it working (at least it did for me, as I could replicate similar Uglify issues by just using es2017
):
presets: ['es2015', 'es2017', 'react'],
plugins: ['transform-runtime', 'transform-decorators-legacy', 'transform-class-properties']
来源:https://stackoverflow.com/questions/38879629/minify-es2017-with-gulp