#
Creating TasksEach gulp task is an asynchronous JavaScript function - a function that accepts an error-first callback or returns a stream, promise, event emitter, child process, or observable (more on that later). Due to some platform limitations, synchronous tasks aren't supported, though there is a pretty nifty alternative.
#
ExportingTasks can be considered public or private.
- Public tasks are exported from your gulpfile, which allows them to be run by the
gulp
command. - Private tasks are made to be used internally, usually used as part of
series()
orparallel()
composition.
A private task looks and acts like any other task, but an end-user can't ever execute it independently. To register a task publicly, export it from your gulpfile.
#
Compose tasksGulp provides two powerful composition methods, series()
and parallel()
, allowing individual tasks to be composed into larger operations. Both methods accept any number of task functions or composed operations. series()
and parallel()
can be nested within themselves or each other to any depth.
To have your tasks execute in order, use the series()
method.
For tasks to run at maximum concurrency, combine them with the parallel()
method.
Tasks are composed immediately when either series()
or parallel()
is called. This allows variation in the composition instead of conditional behavior inside individual tasks.
series()
and parallel()
can be nested to any arbitrary depth.
When a composed operation is run, each task will be executed every time it was referenced. For example, a clean
task referenced before two different tasks would be run twice and lead to undesired results. Instead, refactor the clean
task to be specified in the final composition.
If you have code like this:
Migrate to this: