Gulp conventions

I am a little confused on how to best set up the conventions in the gulp file and use some clarification.

Am I correct that you cannot make normal if statements inside a pipe chain? If you can, how would you print it?

I am currently using gulp-if to do something like this:

// Minify
.pipe( gulpif(env === 'production',
    minifyCSS({keepSpecialComments:0,})
))

// Rename
.pipe( gulpif(env === 'production',
    rename({suffix: '.min'})
))

      

But these two blocks will be optimally located within the same condition. Is it possible? I can't seem to get this to work.

+3


source to share


2 answers


You can use lazypipe for transforms minify

and rename

. It will be something like this:



var minifyAndRenameCSS = lazypipe()
  .pipe(minifyCSS({keepSpecialComments:0})
  .pipe(rename({suffix: '.min'}));

gulp.task('build', function() {
  return gulp.src('*.css')
    .pipe(gulpif(env === 'production', minifyAndRenameCSS()))
});

      

+3


source


Base at https://www.npmjs.com/package/lazypipe

minifyAndRenameCSS

it should be:

var minifyAndRenameCSS = lazypipe()
  .pipe(minifyCSS, {keepSpecialComments: 0})
  .pipe(rename, {suffix: '.min'});

      



There should be no function calls inside the pipes. If the function needs some arguments, separate them with commas (i.e. .pipe(myFunc, arg1, arg2)

).

Perhaps you have the correct answer, I'm just sharing so that other viewers know.

+1


source







All Articles