Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to perform multiple gulp commands in one task

Tags:

gulp

I'm having a hard time to understand on how to process multiple gulp sources in a single task. In a task like this:

gulp.task('task1', function (cb) {
    gulp.src('src/js/**/*').pipe(gulp.dest('dist'));
    gulp.src('src/css/**/*').pipe(gulp.dest('dist'));
    ...
});

I would like to process all the different source files and then mark the task as finished, so the others tasks can depend on it's completion.

I'm aware of the possibility, to using individual tasks for each individual source but this would make everything more complicated and bloat the orchestrator with a huge number of tasks that are actually not needed individually.

like image 256
doberkofler Avatar asked Sep 07 '14 17:09

doberkofler


1 Answers

You can pass an array of globs to gulp.src if you are doing the same things to all files. For example,

gulp.task('task1', function () {
  return gulp.src(['src/js/**/*', 'src/css/**/*']).pipe(gulp.dest('dist'));
});

Be sure to return the stream so the orchestrator knows when that task is complete.

If you are doing different things to the different sets of files, you can merge the streams like this in one task:

var es = require('event-stream');
gulp.task('fancy-task', function () {
  return es.merge(
      gulp.src('*.js').pipe(some-js-plugin()),
      gulp.src('*.css').pipe(some-style-plugin))
      .pipe(gulp.dest('dist'));
});
like image 187
ahaurw01 Avatar answered Sep 18 '22 01:09

ahaurw01