Gulp Task Compositions
Gulp tasks can be combined into groups (compositions), where tasks are executed either sequentially or in parallel.
Let's see how this is done. For an example, let's take the following tasks:
function task1(cb) {
cb();
}
function task2(cb) {
cb();
}
Sequential Execution
The series
function is intended for the sequential execution of tasks.
This function takes any number of tasks as parameters and executes
them one after another in the order they are listed.
First, this function needs to be imported from the Gulp library:
const { series } = require('gulp');
Now we can use this function:
function taskD(cb) {
series(task1, task2);
cb();
}
exports.default = taskD;
You can immediately export the result of
series
without creating an extra function
for the public task:
exports.default = series(task1, task2);
Create three tasks that execute sequentially one after the other.
Parallel Execution
The similar function parallel()
is intended for parallel task execution. Let's
look at how it works.
First, let's import it:
const { parallel } = require('gulp');
Let's use our function inside a public task:
function taskD(cb) {
parallel(task1, task2);
cb();
}
exports.default = taskD;
Or simply export the result:
exports.default = parallel(task1, task2);
Create three tasks that execute in parallel.
Combinations
The series
and parallel()
functions
can be nested within each other in any combinations,
for example, like this:
exports.default = series(task1, parallel(task2, task3));
Create five tasks. Come up with examples of combinations using these tasks.