Run a series of dependent gulp tasks in order
Runs a sequence of gulp tasks in the specified order. This function is designed to solve the situation where you have defined run-order, but choose not to or cannot use dependencies.
Be aware that this solution is a hack, and may stop working with a future update to gulp.
Each argument to
run-sequence is run in order. This works by listening to the
task_err events, and keeping track of which tasks have been completed. You can still run some of the tasks in parallel, by providing an array of task names for one or more of the arguments.
If the final argument is a function, it will be used as a callback after all the functions are either finished or an error has occurred.
In version 1.0 I've added a check that prevents the same task from showing up within any sequence. This is to help reduce typo errors, as well as prevent the silent exit bug when the same task occurred twice in a parallel sequence. The sequence will now fail immediately during the validation stage.
If this breaking change affects you, you'll need to take one of several actions:
run-sequenceversion 0.3.7 if it was working for you.
I welcome feedback if this change is a problem for your setup!
run-sequence as a development dependency:
npm install --save-dev run-sequence
Then add use it in your gulpfile, like so (note these are only examples, please check the documentation for your functions for the correct way to use them):
var gulp = ;var runSequence = ;var del = ;var fs = ;// This will run in this order:// * build-clean// * build-scripts and build-styles in parallel// * build-html// * Finally call the callback functiongulp;// configure build-clean, build-scripts, build-styles, build-html as you wish,// but make sure they either return a stream or promise, or handle the callback// Example:gulp;gulp;gulp;
If you have a complex gulp setup with your tasks split up across different files, you may get the error that
run-sequence is unable to find your tasks. In this case, you can configure
run-sequence to look at the gulp within the submodule, like so:
// submodule tasks/mygulptask.jsvar gulp = // might be a different instance than the toplevel one// this uses the gulp you providerunSequence = ;// ...and then use normally;