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
Takes a path string, an array of path strings, a [glob][node-glob] string or an array of [glob][node-glob] strings as `globs` to watch on the filesystem. Also optionally takes `options` to configure the watcher and a `fn` to execute when a file changes.
In the example, `gulp.watch` runs the function returned by `gulp.parallel` each
519
518
time a file with the `js` extension in `js/` is updated.
520
519
521
-
#### glob
520
+
#### globs
522
521
Type: `String` or `Array`
523
522
524
-
A single globor array of globs that indicate which files to watch for changes.
523
+
A path string, an array of path strings, a [glob][node-glob] string or an array of [glob][node-glob] strings that indicate which files to watch for changes.
525
524
526
525
#### opts
527
526
Type: `Object`
528
527
528
+
*`delay` (milliseconds, default: `200`). The delay to wait before triggering the fn. Useful for waiting on many changes before doing the work on changed files, e.g. find-and-replace on many files.
529
+
*`queue` (boolean, default: `true`). Whether or not a file change should queue the fn execution if the fn is already running. Useful for a long running fn.
530
+
*`ignoreInitial` (boolean, default: `true`). If set to `false` the `fn` is called during [chokidar][chokidar] instantiation as it discovers the file paths. Useful if it is desirable to trigger the `fn` during startup. __Passed through to [chokidar][chokidar], but defaulted to `true` instead of `false`.__
531
+
529
532
Options that are passed to [`chokidar`][chokidar].
530
533
531
534
Commonly used options:
@@ -548,17 +551,21 @@ Read about the full set of options in [`chokidar`'s README][chokidar].
548
551
#### fn
549
552
Type: `Function`
550
553
551
-
An [async](#async-support) function to run when a file changes. Does not provide
552
-
access to the `path` parameter.
554
+
If the `fn` is passed, it will be called when the watcher emits a `change`, `add` or `unlink` event. It is automatically debounced with a default delay of 200 milliseconds and subsequent calls will be queued and called upon completion. These defaults can be changed using the `options`.
555
+
556
+
The `fn` is passed a single argument, `callback`, which is a function that must be called when work in the `fn` is complete. Instead of calling the `callback` function, [async completion][async-completion] can be signalled by:
557
+
* Returning a `Stream` or `EventEmitter`
558
+
* Returning a `Child Process`
559
+
* Returning a `Promise`
560
+
* Returning an `Observable`
561
+
562
+
Once async completion is signalled, if another run is queued, it will be executed.
553
563
554
-
`gulp.watch` returns a wrapped [chokidar] FSWatcher object. If provided,
555
-
the callback will be triggered upon any `add`, `change`, or `unlink` event.
556
-
Listeners can also be set directly for any of [chokidar]'s events, such as
557
-
`addDir`, `unlinkDir`, and `error`. You must set listeners directly to get
564
+
`gulp.watch` returns a wrapped [chokidar] FSWatcher object. Listeners can also be set directly for any of [chokidar]'s events, such as `addDir`, `unlinkDir`, and `error`. You must set listeners directly to get
558
565
access to chokidar's callback parameters, such as `path`.
559
566
560
567
```js
561
-
var watcher =gulp.watch('js/**/*.js', gulp.parallel('uglify', 'reload'));
568
+
var watcher =gulp.watch('js/**/*.js', gulp.parallel('concat', 'uglify'));
562
569
watcher.on('change', function(path, stats) {
563
570
console.log('File '+ path +' was changed');
564
571
});
@@ -815,3 +822,4 @@ module.exports = new MyCompanyTasksRegistry();
0 commit comments