How to use the watch function from chokidar

Find comprehensive JavaScript chokidar.watch code examples handpicked from public code repositorys.

262
263
264
265
266
267
268
269
270
271
  }

  return site.generate();
})
.then(() => {
  const watcher = chokidar.watch(rootFolder, {
    ignored: [
      logsFolder,
      outputFolder,
      /(^|[/\\])\../,
fork icon105
star icon94
watch icon13

361
362
363
364
365
366
367
368
369
370
 * Watches all the fragment.js files for changes and updates the fragments file
 * that Gatsby is watching, which then triggers Gatsby to refresh its queries
 */
const watchFragments = () => {
  const fragmentGlob = path.join(componentsFolder, "*", "fragment.js")
  const watcher = chokidar.watch(fragmentGlob)
  watcher.on("change", () => {
    createFragments()
  })
}
fork icon0
star icon0
watch icon1

+ 9 other calls in file

29
30
31
32
33
34
35
36
37
38
}
/**
 * 监听pages目录文件夹变化,重新生成路由
 */
function doWatch(pagesPath){
    var vueWatcher = chokidar.watch(pagesPath+'/**/*.@(vue|js)', {ignoreInitial: true ,persistent: true});
    vueWatcher
        .on('add', path => smartRun(1))
        .on('unlink', path => smartRun(4));
    var dirWatcher = chokidar.watch(pagesPath+'/**', {ignoreInitial: true ,persistent: true});
fork icon0
star icon0
watch icon3

+ 9 other calls in file

70
71
72
73
74
75
76
77
78

if (process.env.TEST) {
  watchOptions.useFsEvents = false;
}

var watcher = chokidar.watch(
  dirs,
  Object.assign({}, watchOptions, config.options.watchOptions || {})
);
fork icon0
star icon0
watch icon0

+ 4 other calls in file

99
100
101
102
103
104
105
106
107
108
  const reschedule = () => {
    if (timeout)
      clearTimeout(timeout);
    timeout = setTimeout(callback, 500);
  };
  chokidar.watch([...paths, ...mustExist, onChange.script].filter(Boolean).map(filePath)).on('all', reschedule);
  callback();
}

for (const { files, from, to, ignored } of copyFiles) {
fork icon0
star icon0
watch icon0

+ 11 other calls in file

1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
  ignored: this.watchOptions.ignored,
  usePolling,
  interval,
};

const watcher = chokidar.watch(watchPath, watchOptions);
// disabling refreshing on changing the content
if (this.options.liveReload !== false) {
  watcher.on('change', () => {
    this.sockWrite(this.sockets, 'content-changed');
fork icon0
star icon0
watch icon1

+ 3 other calls in file

140
141
142
143
144
145
146
147
148
149
    // ages to crawl. So we create our own watcher on the files
    // instead.
    const copy = () => {
        cpx.copy(errCheck);
    };
    chokidar.watch(source).on("add", copy).on("change", copy).on("ready", cb).on("error", errCheck);
} else {
    cpx.on("watch-ready", cb);
    cpx.on("watch-error", cb);
    cpx.watch();
fork icon0
star icon0
watch icon1