Gulp -uglify does not yet have official support for ECMAScript 2015 (aka ES6, aka Harmony), but with a little modification you can use the on-development repository.
How to:
- Open the console and enter
cd node_modules/gulp-uglify
- Edit package.json
dependencies": { "uglify-js": "git+https://github.com/mishoo/UglifyJS2.git#harmony" },
- Console enter:
npm update
And he is ready to run .pipe(uglify()) again
Alternative solution
- Download the following via
npm :
npm install --save-dev gulp-uglify gulp-babel babel-preset-es2015
- Add the following to
gulpfile.js :
var babel = require('gulp-babel'), uglify = require('gulp-uglify');
- The gulp task will be as follows:
gulp.task('uglify', function(){ gulp.src('*.js') .pipe(babel({ presets: ['es2015'] })) .pipe(uglify().on('error', function(e){ console.log(e); })) .pipe(gulp.dest('js')); });
What this means is translating all of JS EcmaScript 2015 code into EcmaScript5, and then guessing it.
source share