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.
Asked
Active
Viewed 5,203 times
21

Michał Perłakowski
- 88,409
- 26
- 156
- 177

Leon Revill
- 1,950
- 3
- 18
- 25
-
Could you change the accepted answer to [this](http://stackoverflow.com/a/39169594/3853934)? – Michał Perłakowski Dec 10 '16 at 20:28
2 Answers
25
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'))
})

Gabriel Furstenheim
- 2,969
- 30
- 27
-
1you need to add `npm install babili --save-dev` to your answer so that we don't have to click off-site – activedecay Jan 13 '17 at 22:07
-
I also had to do `npm install gulp-babel --save-dev` and `var babel = require('gulp-babel');` to make this to work. :) – Abhi Jun 07 '17 at 08:26
-
0
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

ManuRGDev
- 535
- 4
- 10
-
-
@nguyên 'cause the response is now deprecated. New one is down comment – ManuRGDev Mar 10 '17 at 22:34
-