This is an answer to https://twitter.com/tinkeraway/status/701746408072855552:
Calling npm run foo -- [something]
just calls whatever is defined under the foo
script and adds [something]
to the end.
So if you have this in your scripts
:
{
"foo": "webpack"
}
Calling npm run foo
will run webpack
, and npm run foo -- -w
will run webpack -w
.
Npm does not implement any watch features itself, but many command line utilities (such as webpack, browserify, node-sass, etc.) have implemented watch you can trigger with a --watch
/-w
argument.
If you need to watch some files and run an arbitrary command when they change, you can use a package like chokidar-cli.
Here is an example:
{
"foo": "foo ./blah",
"watchfoo": "chokidar \"**/*.js\" -c \"npm run foo\""
}
Note that on windows, you should use (escaped) double quotes, but if you don't care about supporting windows, single quotes are fine.
Brilliant. Too many new/unknown libs in at once, and nothing made sense when stuck. Thanks a bunch.