gulp:条件语句插件——gulp-if

Condition条件判断

Only uglify the content if the condition is true, but send all the files to the dist folder

(如果条件为真,只修改内容,但将所有文件发送到dist文件夹)

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三元判断

If condition returns true, uglify else beautify, then send everything to the dist folder

(如果条件返回true,uglify否则beautity,然后发送到dist文件夹)

var gulpif = require('gulp-if');
var uglify = require('gulp-uglify');
var beautify = require('gulp-beautify');
 
var condition = function (file) {
  // TODO: add business logic
  return true;
}
 
gulp.task('task', function() {
  gulp.src('./src/*.js')
    .pipe(gulpif(condition, uglify(), beautify()))
    .pipe(gulp.dest('./dist/'));
});

 

你可能感兴趣的:(gulp,gulp,gulp-if)