Search code examples
gulp

Gulp - How do i chain together tasks or streams that use different src?


I want to all perform actions in stream but from multiple sources then deploy all at the end, how can i do that in gulp either in the same task or by combining tasks?

For example:

return gulp.src('/dir1/*.js')
  .pipe(..)
  .pipe(..)
  .gulp.src('/dir2/*.css') 
  .pipe(gif('some-particular-file.css', xxx))
  .pipe(gulp.dest(''));

also let me add that I dont want to have to filter like this:

   gulp.src(['/dir1/*.js', '/dir2/*.css'])
       .pipe(gif(*.js, xxx)
       .pipe(gif(*.css, xxx)
       .gulp.dest('appy'));

Solution

  • gulp 3.x

    Use the gulp-add-src package:

    var addSrc = require('gulp-add-src');
    
    return gulp.src('/dir1/*.js')
      .pipe(..)
      .pipe(..)
      .pipe(addSrc('/dir2/*.css')) 
      .pipe(gif('some-particular-file.css', xxx))
      .pipe(gulp.dest(''));
    

    gulp 4.x

    gulp.src() can act as a passthrough stream by using the passthrough option:

    return gulp.src('/dir1/*.js')
      .pipe(..)
      .pipe(..)
      .pipe(gulp.src('/dir2/*.css', {passthrough:true})) 
      .pipe(gif('some-particular-file.css', xxx))
      .pipe(gulp.dest(''));