用吞噬将es2017缩小 [英] minify es2017 with gulp

查看:211
本文介绍了用吞噬将es2017缩小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,我正在使用uglify-gulp和babel来缩小我的js。它与es2015和es2016非常相称。但是如果我尝试做es2017就会中断。

有谁知道任何解决方法来缩小使用es2017中的新实验性功能的js?

  gulp.src('build / js / bundled / bundle.js')
.pipe(babel({
compact:false,
预设:[es2017,react],
plugins:[transform-decorators-legacy],
}))
.pipe(uglify())
.pipe(gulp.dest('build / js / bundled'));

产生这个错误

  GulpUglifyError:无法缩小JavaScript 

如果我将es2017更改为es2015 / es2016它会缩小我没有es2017功能的捆绑套件。但我希望能够使用这些实验性功能并能够缩小我的代码。我认为Uglify不能解析一些ES2015的功能,所以你需要将它们转换成ES5( es2017 目标Node 5 +)。

通过这些webpack说明,特别是预设和插件,您应该能够获得它工作(至少它为我做了,因为我可以通过使用 es2017 来复制类似的Uglify问题):



<$ p'p> 预设:['es2015','es2017','react'],
插件:['transform-runtime','transform-decorators-legacy','transform- class-properties']


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

解决方案

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']

这篇关于用吞噬将es2017缩小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆