gulprun-sequence

Gulp Task Order - Serial & Parallel


I've got the following tasks that are being ran by Gulp.

  1. script-a
  2. script-b
  3. script-c

script-a is unrelated (relatively speaking) to tasks b and c, and takes around 5 seconds to run.

script-b and script-c are related so have to be ran in serial, and take around a second each to run.

Therefore, I want to be able to run a in parallel with b and c - while maintaining the latter two in serial.

I'm currently using runSequence to run them all in series;

gulp.task('script', function(callback) {
  return runSequence(
    'script-a',
    'script-b',
    'script-c',
    callback
  )
});

I can get script-a to run in parallel with one of the other tasks like so;

gulp.task('script', function(callback) {
  return runSequence(
    ['script-a', 'script-b'],
    'script-c',
    callback
  )
});

But that seems to be only half solving the problem. Seems like the answer should be obvious?


Solution

  • You can try grouping script-b and script-c in another task and then run parallel in the task script. Something like this:

    // script-b and script-c run in serial
    gulp.task('scriptsBC', function(callback){
      return runSequence(
        'script-b',
        'script-c',
        callback
      )
    })
    
    // script-a and scriptBC run in paralell
    gulp.task('script', function(callback) {
      return runSequence(
        ['script-a','scriptsBC'],
        callback
      )
    });