Taking the following scripts section from a package.json
:
"scripts":{
"sass:watch": "npm run sass -- -w ./src/public/stylesheets -r --source-map true",
"livereload": "live-reload --port 9091 ./src/**/*",
"dev:watch" : "npm run sass:watch; npm run livereload"
}
How can I successfully get both the sass:watch
and livereload
tasks to run, without blocking each other, from the dev:watch
task?
Currently, when I run npm run dev:watch
sass:watch
blocks livereload
.
If I reorder them, the same problem occurs.
Use a single ampersand:
"dev:watch" : "npm run sass:watch & npm run livereload"
&&
runs tasks in serial;&
in parallel.Use parallelshell.
Here's how I'm doing it.
With live-server it'll look like:
Take a look at Grunt Concurrent
you could try the concurrently package for npm
then use it to run both of your script:
you can find info about the package here: https://www.npmjs.com/package/concurrently
This is what I use for small npm script based projects: I simply run
npm start
and start working ;)concurrently
launches the corresponding tasks in parallelnode-sass
is responsible for the sass->css generation--watch
option for monitoring ofsass
related changeslite-server
starts the server with the build-in live-reload support. By default, it watches for changes for the following file extensions:html,htm,css,js
, but everything can be easily adjusted with the configuration filesbs-config.json
orbs-config.js
.Relevant parts of the
package.json
:This works well for me on Windows 10 and as well as on the GNU/Linux based distros like Ubuntu.
AFAIK, you can't, in a useful way.
You could push one task to the background by appending
&
to its command line, but that would keep the task running even when you^C
to stop the running NPM task.Alternatively, you can call
npm run ...
twice and bg one:But that's pretty messy too IMO.
If you want this sort of thing, consider using
gulp
.