Minify (not transpile) ES2015 code with Gulp

后端 未结 2 2005
轻奢々
轻奢々 2021-02-07 03:02

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.

相关标签:
2条回答
  • 2021-02-07 03:18

    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

    0 讨论(0)
  • 2021-02-07 03:24

    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'))
    })
    
    0 讨论(0)
提交回复
热议问题