Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gulp: passing dependent task return stream as parameter

Tags:

gulp

I'm trying to create two gulp tasks, and I'd like the second task to take the first one's output stream and keep applying plugins to it.

Can I pass the first task's return value to the second task?

The following doesn't work:

// first task to be run
gulp.task('concat', function() {
  // returning a value to signal this is sync
  return
    gulp.src(['./src/js/*.js'])
      .pipe(concat('app.js'))
      .pipe(gulp.dest('./src'));
};

// second task to be run
// adding dependency
gulp.task('minify', ['concat'], function(stream) {
  // trying to get first task's return stream
  // and continue applying more plugins on it
  stream
    .pipe(uglify())
    .pipe(rename({suffix: '.min'}))
    .pipe(gulp.dest('./dest'));
};

gulp.task('default', ['minify']);

Is there any way to do this?

like image 923
AmitK Avatar asked Nov 01 '22 03:11

AmitK


1 Answers

you can't pass stream to other task. but you can use gulp-if module to skip some piped method depending on conditions.

var shouldMinify = (0 <= process.argv.indexOf('--uglify'));

gulp.task('script', function() {
  return gulp.src(['./src/js/*.js'])
      .pipe(concat('app.js'))
      .pipe(gulpif(shouldMinify, uglify())
      .pipe(gulpif(shouldMinify, rename({suffix: '.min'}))
      .pipe(gulp.dest('./dest'));
});

execute task like this to minify

gulp script --minify
like image 157
yshrsmz Avatar answered Nov 08 '22 14:11

yshrsmz