Minify (not transpile) ES2015 code with Gulp

做~自己de王妃 提交于 2019-12-03 04:41:59

It is now possible to minify ES2015 without transpiling the code. babel minify (previously babili) is a babel preset that does that.

To install do:

npm install --save-dev babel-preset-minify

To use it with gulp you do:

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

Currently, the only way to minify ES2015 with gulp is to use gulp-babel which will transform ES2015 to "traditional" Javascript and then use gulp-uglify and gulp-minify.

Learn more at: gulp-babel

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