Search code examples
uglifyjsgulp-uglify

Cannot invoke custom compressor option 'unused' in gulp-uglify


I've passed an object to gulp-uglify to specify a compressor option, just as the docs instruct. Doesn't seem to be working.

I would like to set the option unused: false in order to process a form validation function referenced by the onsubmit attribute of the form element. For reasons that escape me, gulp-uglify will not honor the option.

Here is the task I've set:

gulp.task('js', function (cb) {
    pump([
        gulp.src('./js/app.js'),
        gulpBrowser.browserify(),
        babel({ presets: ['es2015'] }),
        uglify({compressor: { unused: false } }).on('error', function(e) {
            console.log(e);
        }),
        gulp.dest('../public/js/')
    ]);
});

Solution

  • So, it appears I had the compressor property spelled incorrectly; compress: { unused: false } is the correct usage. Also, if you're using pump,if you're passing a callback, you don't need to attach an error handler. I had some old code cobbled together trying to figure out this mess.

    Corrected task:

    gulp.task('js', function (cb) {
        pump([
            gulp.src('./js/app.js'),
            gulpBrowser.browserify(),
            babel({ presets: ['es2015'] }),
            uglify({compress: { unused: false } }),
            gulp.dest('../public/js/')
        ], cb);
    });