使用Gulp缩小(不可变)ES2015代码 [英] Minify (not transpile) ES2015 code with Gulp

查看:119
本文介绍了使用Gulp缩小(不可变)ES2015代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将ES2015代码缩小到ES5?流行的 gulp-minify gulp-uglify 模块不能简单地缩小ES2015代码。

How to minify ES2015 code without transpiling it to ES5? The popular gulp-minify and gulp-uglify modules do not work with simply minifying ES2015 code.

推荐答案

现在可以在不打破代码的情况下将ES2015缩小。 Babili 是一个babel预设,可以这样做。

It is now possible to minify ES2015 without transpiling the code. Babili is a babel preset that does that.

使用它你会做的:

var gulp = require('gulp')
var babel = require('gulp-babel')
gulp.task('default', () => {
  return gulp.src('src/app.js')
  .pipe(babel({presets: ['babili']}))
  .pipe(gulp.dest('dist'))
})

这篇关于使用Gulp缩小(不可变)ES2015代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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