Reputation: 73908
I have a task in gulp that need to execute other two tasks consecutively and in order.
So when I run build
, build
run first task-a
, when task-a
is completed
task-b
is performed.
At the moment I am using this script, I would like to have confirmation the is correct.
gulp.task('build', [
'task-a',
'task-b'
]);
Upvotes: 0
Views: 2846
Reputation: 9989
As stated at the official documentation with that format the tasks will run in parallel (all at once), so don't assume that the tasks will start/finish in order.
You have to explicitly define the order of tasks as follow to make Gulp workout the right order:
gulp.task('task-a', function(){ ... });
gulp.task('task-b', ['task-a'], function(){ ... });
gulp.task('build', ['task-a', 'task-b'], function(){ ... });
At this point when you'll try to run build
Gulp will build the dependency tree of the tasks and workout that task-b
relies on task-a
to be completed before executing.
A more complete example can be found here: https://github.com/gulpjs/gulp/blob/master/docs/recipes/running-tasks-in-series.md
Upvotes: 1
Reputation: 4318
The current gulp task you have at the moment will run correctly, it'll run task-a
then run task-b
. For whatever reason, it's not giving you back what you want. There's also an npm package called run-sequence
(https://www.npmjs.com/package/run-sequence) you can use.
Your gulp task would look something like :
gulp.task('runTasks', function () {
runSequence('task-a', 'task-b', 'task-c');
});
And that'll execute your tasks in the order sequence you pass it.
Upvotes: 0