gulp-uglify

Minify JavaScript with UglifyJS3.

Installation

npm install --save-dev gulp-uglify

Configuration

Conditionally filter content

var gulpif = require('gulp-if');
var uglify = require('gulp-uglify');

var condition = true; // TODO: add business logic

gulp.task('task', function() {
  gulp.src('./src/*.js')
    .pipe(gulpif(condition, uglify()))
    .pipe(gulp.dest('./dist/'));
});

Ternary filter

var gulpif = require('gulp-if');
var uglify = require('gulp-uglify');

var condition = function (file) {
  // TODO: add business logic
  return true;
}

gulp.task('task', function() {
  gulp.src('./src/*.js')
    .pipe(gulpif(condition, uglify()))
    .pipe(gulp.dest('./dist/'));
});