Combine two sips into one

I have the following gulp task:

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

      

How can I combine the two gulpif()

into one?

+3


source to share


2 answers


The recommended way to do it: lazypipe according to gulp-if

the documentation itself
:

Lazypipe creates a function that initializes the pipe chain when used. This allows you to chain events inside a gulp-if condition.



In this example:

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

      

+2


source


I think gulp plugins are object streams, so you can get away with



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

      

0


source







All Articles