@wuyuchentr/file-watcher-lite
v1.0.0
Published
Lightweight file/directory watcher with debounce, recursive, and filter support. ~80% lighter than chokidar.
Downloads
91
Maintainers
Readme
@wuyuchentr/file-watcher-lite
Lightweight file/directory watcher — ~80% lighter than chokidar.
Built on fs.watch with debounce, recursive watching, and file filtering. Zero dependencies.
Install
npm install @wuyuchentr/file-watcher-liteUsage
const { watch } = require('@wuyuchentr/file-watcher-lite');
const w = watch('./src', { recursive: true, debounce: 100 });
w.on('change', (ev) => console.log('changed:', ev.path));
w.on('unlink', (ev) => console.log('deleted:', ev.path));
// Stop
w.close();Events
| Event | Description |
|-------|-------------|
| change | File modified or added |
| unlink | File deleted |
| all | All events |
Options
| Option | Default | Description |
|--------|---------|-------------|
| recursive | true | Watch subdirectories |
| debounce | 100 | Debounce interval in ms |
| filter | — | Glob / Regex / Function / Array — include only matching files |
| ignore | — | Glob / Regex / Function / Array — exclude matching files |
Filter examples
// Regex
watch('./src', { filter: /\.js$/ })
// Glob
watch('./src', { filter: '*.js' })
// Multiple patterns
watch('./src', { filter: ['*.js', '*.ts'], ignore: '*.test.js' })
// Function
watch('./src', {
filter: (p) => p.endsWith('.js') && !p.includes('/node_modules/'),
})Comparison
| | chokidar | this | |---|----------|------| | Bundle size | ~200 KB | ~2 KB | | Dependencies | 7+ | 0 | | Polling fallback | ✓ | ✗ | | macOS | ✓ | ✓ | | Linux (recursive) | ✓ | Node ≥ 19 | | Windows | ✓ | ✓ |
