Use glob patterns to watch file sets and run a command when anything is added, changed or deleted.
npm install onchange# On every change run `npm test`.
onchange 'app/**/*.js' 'test/**/*.js' -- npm test
# On every change restart `server.js` (by killing the running process).
onchange -i -k '**/*.js' -- node server.js
# On every change `echo` file change.
onchange '**/*.js' -- echo '{{event}} to {{file}}'NOTE: Windows users may need to use double quotes rather than single quotes. If used in an npm script, remember to escape the double quotes.
You can match as many glob patterns as you like, just put the command you want to run after the -- and it will run any time a file matching any of the globs is added changed or deleted.
Other available replacement variables are fileExt
(path.extname(file)), fileBase (path.basename(file)),
fileBaseNoExt (basename, without extension), and fileDir
(path.dirname(file)).
To execute the command for all initially added paths:
onchange -a 'config.json' -- microservice-proxy -c {{file}} -p 9000To execute the command once on load without any event:
onchange -i '**/*.js' -- npm startTo exclude matches:
onchange '**/*.ts' -e 'dist/**/*.js' -- tslint**/node_modules/** and **/.git/** are excluded by default, use --no-exclude to disable:
onchange 'node_modules/**' --no-exclude -- tslintExcludes all paths in a file following the .gitignore specification.
onchange '**' --exclude-path .gitignore -- prettierTo kill current and pending processes between changes:
onchange -k '**/*.js' -- npm testSet the maximum concurrent processes to run (default is 1):
onchange -j2 '**/*.js' -- cp -v -r '{{file}}' 'test/{{file}}'To set the amount of delay (in ms) between process changes:
onchange -d 1000 '**/*.js' -- npm startTo hold the events until the size does not change for a configurable amount of time (in ms, default is 2000):
onchange --await-write-finish 1500 '**/*.js' -- npm testUse polling to monitor for changes. This option is useful if you're watching an NFS volume.
onchange -p 100 '**/*.js' -- npm testShell command to execute every change:
onchange -o '> .changelog' 'src/**/*.js' -- echo '{{event}} to {{file}}'P.S. When a command is used with --outpipe, the stdout from the command will be piped into outpipe.
By default, onchange watches for all events from chokidar. Use this option to watch only for events you need:
onchange -f add -f change '**/*.js' -- npm startEnable if you want verbose logging from onchange (useful for debugging). For example:
onchange -v 'app/**/*.js' 'test/**/*.js' -- npm testIncludes types for TypeScript users.
- cli-error-notifier - Send native desktop notifications if a command exits with an exit code other than
0.
MIT