0

I'm trying to minify all of my AngularJS files to be compressed with gulp-uglify. But the problem is I've used ES6 syntax in my project, especially arrow function.

When I minify js file with as follow:

gulp.task('minify-scripts', function() {
  return gulp.src(jsFiles)
    .pipe(concat('scripts.js'))
    .pipe(gulp.dest(jsDest))
    .pipe(rename('scripts.min.js'))
    .pipe(uglify())
    .pipe(gulp.dest(jsDest));
});

for following ES6 code:

 apiService.fetchAccessToken($scope.body).then((response) => {

encountered following error:

events.js:160 throw er; // Unhandled 'error' event

But when I reversed ES6 code to traditional code:

 apiService.fetchAccessToken($scope.body).then(function(response) {

Everything is working fine. Please let me know what I've missed to configure something inside gulp to minify es6 code?

PPShein
  • 13,309
  • 42
  • 142
  • 227
  • 1
    Possible duplicate of [How to minify ES6 functions with gulp-uglify?](https://stackoverflow.com/questions/44958216/how-to-minify-es6-functions-with-gulp-uglify) – 31piy Apr 30 '18 at 04:46
  • You may try to follow [this thread](https://github.com/mishoo/UglifyJS2/issues/659). I think this issue was with older versions. Can you verify? – 31piy Apr 30 '18 at 04:47

1 Answers1

0

According to the github README of gulp-uglify, you should use uglify-es for ES6 support.

// can be a git checkout // or another module (such as uglify-es for ES6 support)