简体   繁体   中英

How to pipe input to uglify-js-harmony in gulp

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.

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
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM