@@ -493,6 +493,9 @@ A task name, a function or an array of either.
493493### gulp.watch(glob[ , opts] , fn)
494494
495495Watch files and do something when a file changes.
496+ File watching is provided by the [ ` chokidar ` ] [ chokidar ] module.
497+ Please report any file watching problems directly to its
498+ [ issue tracker] ( https://github.com/paulmillr/chokidar/issues ) .
496499
497500``` js
498501gulp .watch (' js/**/*.js' , gulp .parallel (' uglify' , ' reload' ));
@@ -509,7 +512,23 @@ A single glob or array of globs that indicate which files to watch for changes.
509512#### opts
510513Type: ` Object `
511514
512- Options, that are passed to [ ` chokidar ` ] [ chokidar ] .
515+ Options that are passed to [ ` chokidar ` ] [ chokidar ] .
516+
517+ Commonly used options:
518+ * ` ignored ` ([ anymatch] ( https://github.com/es128/anymatch ) -compatible definition)
519+ Defines files/paths to be excluded from being watched.
520+ * ` usePolling ` (boolean, default: ` false ` ). When ` true ` uses a watch method backed
521+ by stat polling. Usually necessary when watching files on a network mount or on a
522+ VMs file system.
523+ * ` cwd ` (path string). The base directory from which watch paths are to be
524+ derived. Paths emitted with events will be relative to this.
525+ * ` alwaysStat ` (boolean, default: ` false ` ). If relying upon the
526+ [ ` fs.Stats ` ] ( http://nodejs.org/api/fs.html#fs_class_fs_stats ) object
527+ that may get passed as a second argument with ` add ` , ` addDir ` , and ` change ` events
528+ when available, set this to ` true ` to ensure it is provided with every event. May
529+ have a slight performance penalty.
530+
531+ Read about the full set of options in [ ` chokidar ` 's README] [ chokidar ]
513532
514533#### fn
515534Type: ` Function `
@@ -518,15 +537,13 @@ An [async](#async-support) function to run when a file changes.
518537
519538` gulp.watch ` returns a wrapped [ chokidar] FSWatcher object. If provided,
520539the callback will be triggered upon any ` add ` , ` change ` , or ` unlink ` event.
521- Listeners can also be set directly for any of [ chokidar] 's events.
540+ Listeners can also be set directly for any of [ chokidar] 's events, such as
541+ ` addDir ` , ` unlinkDir ` , and ` error ` .
522542
523543``` js
524544var watcher = gulp .watch (' js/**/*.js' , gulp .parallel (' uglify' , ' reload' ));
525545watcher .on (' change' , function (path , stats ) {
526546 console .log (' File ' + path + ' was changed' );
527- if (stats) {
528- console .log (' changed size to ' + stats .size );
529- }
530547});
531548
532549watcher .on (' unlink' , function (path ) {
@@ -544,7 +561,22 @@ Type: Object
544561
545562[ File stats] ( http://nodejs.org/api/fs.html#fs_class_fs_stats ) object when available.
546563Setting the ` alwaysStat ` option to true will ensure that a file stat object will be
547- available.
564+ provided.
565+
566+ #### watcher methods
567+
568+ ##### watcher.close()
569+
570+ Shuts down the file watcher.
571+
572+ ##### watcher.add(glob)
573+
574+ Watch additional glob (or array of globs) with an already-running watcher instance.
575+
576+ ##### watcher.unwatch(glob)
577+
578+ Stop watching a glob (or array of globs) while leaving the watcher running and
579+ emitting events for the remaining paths it is watching.
548580
549581### gulp.tree(options)
550582
0 commit comments