Skip to content

Commit d916276

Browse files
committed
Docs: Add default task wrappers to Watching Files examples to make runnable (ref #2322)
1 parent ea52a92 commit d916276

File tree

1 file changed

+34
-24
lines changed

1 file changed

+34
-24
lines changed

Diff for: docs/getting-started/8-watching-files.md

+34-24
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,12 @@ function css(cb) {
2929
cb();
3030
}
3131

32-
// You can use a single task
33-
watch('src/*.css', css);
34-
// Or a composed task
35-
watch('src/*.js', series(clean, javascript));
32+
exports.default = function() {
33+
// You can use a single task
34+
watch('src/*.css', css);
35+
// Or a composed task
36+
watch('src/*.js', series(clean, javascript));
37+
};
3638
```
3739

3840
## Warning: avoid synchronous
@@ -49,11 +51,13 @@ If you need to use different events, you can use the `events` option when callin
4951
```js
5052
const { watch } = require('gulp');
5153

52-
// All events will be watched
53-
watch('src/*.js', { events: 'all' }, function(cb) {
54-
// body omitted
55-
cb();
56-
});
54+
exports.default = function() {
55+
// All events will be watched
56+
watch('src/*.js', { events: 'all' }, function(cb) {
57+
// body omitted
58+
cb();
59+
});
60+
};
5761
```
5862

5963
## Initial execution
@@ -65,11 +69,13 @@ To execute tasks before the first file change, set the `ignoreInitial` option to
6569
```js
6670
const { watch } = require('gulp');
6771

68-
// The task will be executed upon startup
69-
watch('src/*.js', { ignoreInitial: false }, function(cb) {
70-
// body omitted
71-
cb();
72-
});
72+
exports.default = function() {
73+
// The task will be executed upon startup
74+
watch('src/*.js', { ignoreInitial: false }, function(cb) {
75+
// body omitted
76+
cb();
77+
});
78+
};
7379
```
7480

7581
## Queueing
@@ -81,11 +87,13 @@ To disable queueing, set the `queue` option to `false`.
8187
```js
8288
const { watch } = require('gulp');
8389

84-
// The task will be run (concurrently) for every change made
85-
watch('src/*.js', { queue: false }, function(cb) {
86-
// body omitted
87-
cb();
88-
});
90+
exports.default = function() {
91+
// The task will be run (concurrently) for every change made
92+
watch('src/*.js', { queue: false }, function(cb) {
93+
// body omitted
94+
cb();
95+
});
96+
};
8997
```
9098

9199
## Delay
@@ -97,11 +105,13 @@ To adjust the delay duration, set the `delay` option to a positive integer.
97105
```js
98106
const { watch } = require('gulp');
99107

100-
// The task won't be run until 500ms have elapsed since the first change
101-
watch('src/*.js', { delay: 500 }, function(cb) {
102-
// body omitted
103-
cb();
104-
});
108+
exports.default = function() {
109+
// The task won't be run until 500ms have elapsed since the first change
110+
watch('src/*.js', { delay: 500 }, function(cb) {
111+
// body omitted
112+
cb();
113+
});
114+
};
105115
```
106116

107117
## Using the watcher instance

0 commit comments

Comments
 (0)