Ulad Melekh
Ulad Melekh

Reputation: 944

Several Gulp tasks wait for another one

I need to build a sequence of Gulp tasks like this:

Task1 -> Task2A, Task2B, Task2C -> Task3,

where tasks 2A,2B,2C run in parallel(but task1 should be completed before, and completed just once).

What I tried:

gulp.task('Task1', []);

gulp.task('Task2A', ['Task1']);

gulp.task('Task2B', ['Task1']);

gulp.task('Task2C', ['Task1']);

gulp.task('Task3', ['Task2A', 'Task2B', 'Task2C']);

Looks like it's working, but I'm not sure, does it guarantee that Task1 will be executed only 1 time, or it can be triggered multiple times?

Thank you.

Upvotes: 0

Views: 98

Answers (2)

Mark
Mark

Reputation: 182591

Perhaps the simplest way to do this (without using gulp4.0) is the run-sequence plugin.

For your case:

var runSequence = require('run-sequence');

gulp.task('build', function(callback) {
   runSequence( 'Task1',
               ['Task2A', 'Task2B', 'Task2C'],
                'Task3',
                callback);
});

Make sure you have return statements in all your tasks.

Please Note

This was intended to be a temporary solution until the release of gulp 4.0 which should have support for defining task dependencies similarly.

Given that Gulp 4 appears to never be fully released, take that for what you will. Be aware that this solution is a hack, and may stop working with a future update to gulp.

Upvotes: 1

lankovova
lankovova

Reputation: 1426

Try this structure

gulp.task('Task1', []);

gulp.task('Task2A', ['Task1']);

gulp.task('Task2B', ['Task2A']);

gulp.task('Task2C', ['Task2B']);

gulp.task('Task3', ['Task2C']);

Also, you can run task inside another task, like this:

gulp.task('task1', function(){
  gulp.start('task2');
})

Upvotes: 0

Related Questions