4

I want to uglify some JS containing classes. This is not supported by gulp-uglify at the moment as discussed here.

I have done . .

npm install uglify-js-harmony --save-dev

as advised in the previous answer, but being new to front end dev in general, I now don't know how to pipe my source through this as I could with gulp-uglify.

I have something like this . .

var uglify = require('uglify-js-harmony');

// ...

gulp.task('scripts', function(){
    return gulp.src(bower().concat(jsFiles))            
        .pipe(plumber())
        .pipe(concat('main.min.js'))
        .pipe(uglify())
        .pipe(gulp.dest(dest + 'js'))
        .pipe(reload({stream:true}))
});

... but it bails saying [17:42:40] TypeError: uglify is not a function, and I'm at a loss on how to proceed. Thanks.

Community
  • 1
  • 1
learnvst
  • 15,455
  • 16
  • 74
  • 121

1 Answers1

-1

It is much easier to just use regular gulp-babel in combination with gulp-uglify . .

$ npm install --save-dev gulp-uglify gulp-babel babel-preset-es2015

Then . . .

var uglify = require('gulp-uglify'),
    babel  = require('gulp-babel');


// ...

gulp.task('scripts', function(){
    return gulp.src(//... src stuff
        .pipe(babel({ presets: ['es2015']}))
        .pipe(uglify()))
        //... other stuff
});
learnvst
  • 15,455
  • 16
  • 74
  • 121
  • 1
    It is much easier, yes, but the regular uglify doesn't understand ES6+ syntax like `for await`, `@decorators` and so on. – kernel Jan 20 '17 at 21:20