You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: docs/api/series.md
+94-20
Original file line number
Diff line number
Diff line change
@@ -5,35 +5,109 @@ hide_title: true
5
5
sidebar_label: series()
6
6
-->
7
7
8
-
# `gulp.series(...tasks)`
8
+
# series()
9
9
10
-
Takes a number of task names or functions and returns a function of the composed
11
-
tasks or functions.
10
+
Combines task functions and/or composed operations into larger operations that will be executed one after another, in sequential order. The composed operations from `series()` and `parallel()` can be nested to any depth.
12
11
13
-
When using task names, the task should already be registered.
12
+
## Usage
14
13
15
-
When the returned function is executed, the tasks or functions will be executed
16
-
in series, each waiting for the prior to finish. If an error occurs,
17
-
execution will stop.
14
+
```js
15
+
const { series } =require('gulp');
16
+
17
+
functionjavascript(cb) {
18
+
// body omitted
19
+
cb();
20
+
}
21
+
22
+
functioncss(cb) {
23
+
// body omitted
24
+
cb();
25
+
}
26
+
27
+
exports.build=series(javascript, css);
28
+
```
29
+
30
+
## Signature
31
+
32
+
```js
33
+
series(...tasks)
34
+
```
35
+
36
+
### Parameters
37
+
38
+
| parameter | type | note |
39
+
|:--------------:|:------:|-------|
40
+
| tasks <br> **(required)**| function <br> string | Any number of task functions can be passed as individual arguments. Strings can be used if you've registered tasks previously, but this is not recommended. |
41
+
42
+
### Returns
43
+
44
+
A composed operation to be registered as a task or nested within other `series` and/or `parallel` compositions.
45
+
46
+
When the composed operation is executed, all tasks will be run sequentially. If an error occurs in one task, no subsequent tasks will be run.
47
+
48
+
### Errors
49
+
50
+
When no tasks are passed, throws an error with the message, "One or more tasks should be combined using series or parallel".
18
51
52
+
When invalid tasks or unregistered tasks are passed, throws an error with the message, "Task never defined".
53
+
54
+
## Forward references
55
+
56
+
A forward reference is when you compose tasks, using string references, that haven't been registered yet. This was a common practice in older versions, but this feature was removed to achieve faster task runtime and promote the use of named functions.
57
+
58
+
In newer versions, you'll get an error, with the message "Task never defined", if you try to use forward references. You may experience this when trying to use `exports` for your task registration *and* composing tasks by string. In this situation, use named functions instead of string references.
59
+
60
+
During migration, you may need to use the [forward reference registry][undertaker-forward-reference-external]. This will add an extra closure to every task reference and dramatically slow down your build. **Don't rely on this fix for very long**.
61
+
62
+
## Avoid duplicating tasks
63
+
64
+
When a composed operation is run, each task will be executed every time it was supplied.
65
+
66
+
A `clean` task referenced in two different compositions would be run twice and lead to undesired results. Instead, refactor the `clean` task to be specified in the final composition.
0 commit comments