将两个gulpif合二为一

时间:2014-12-09 13:55:39

标签: javascript node.js gulp

我有以下gulp任务:

gulp.task('app-scripts', function() {
     return getEnvScriptsStream()
        .pipe(gulpif(stgOrProd(), uglify()))
        .pipe(gulpif(stgOrProd(), concat('embed')))
        .pipe(gulp.dest(paths.js))
        .pipe(connect.reload());
});

如何将两个gulpif()合并为一个?

2 个答案:

答案 0 :(得分:2)

根据lazypipe

,推荐的方法是使用gulp-if documentation itself
  

Lazypipe创建一个在使用时初始化管道链的函数。这允许您在gulp-if条件内创建一系列事件。

对于有问题的例子:

gulp.task('app-scripts', function() {
  return getEnvScriptsStream()
    .pipe(gulpif(stgOrProd(), lazypipe().pipe(uglify).pipe(concat, 'embed')()))
    .pipe(gulp.dest(paths.js))
    .pipe(connect.reload());
});

答案 1 :(得分:0)

我认为gulp插件是对象流,因此您可以使用

gulp.task('app-scripts', function() {
     return getEnvScriptsStream()
        .pipe(gulpif(stgOrProd(), uglify().pipe(concat('embed'))))
        .pipe(gulp.dest(paths.js))
        .pipe(connect.reload());
}); 
相关问题