Skip to content

Commit

Permalink
Add v4 migration guide
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmillr committed Sep 13, 2024
1 parent d70bd87 commit 629b049
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ chokidar.watch('.').on('all', (event, path) => {

// Initialize watcher.
const watcher = chokidar.watch('file, dir, or array', {
ignored: /(^|[\/\\])\../, // ignore dotfiles
ignored: (path, stats) => stats?.isFile() && !path.endsWith('.js'), // only watch js files
persistent: true
});

Expand Down Expand Up @@ -261,6 +261,30 @@ execute a command on each change, or get a stdio stream of change events.

Details in [`.github/full_changelog.md`](.github/full_changelog.md).

If you've used globs before and want do replicate the functionality with v4:

```js
// v3
chok.watch('**/*.js');
chok.watch("./directory/**/*");

// v4
chok.watch('.', {
ignored: (path, stats) => stats?.isFile() && !path.endsWith('.js'), // only watch js files
});
chok.watch('./directory');

// other way
import { glob } from 'node:fs/promises';
const watcher = watch(await glob('**/*.js'));

// unwatching
// v3
chok.unwatch('**/*.js');
// v4
chok.unwatch(await glob('**/*.js'));
```
## Also
Why was chokidar named this way? What's the meaning behind it?
Expand Down

0 comments on commit 629b049

Please sign in to comment.