简体   繁体   中英

'grunt watch' won't run from a package.json script on Windows

I am doing a dev run of a small node app on a Windows machine. I have set up grunt-contrib-watch and can run it successfully from the bash command line by typing 'grunt watch'. It works as expected.

However when I run the following script in my package.json file:

"scripts": {
"start": "node app",
"predev": "grunt",
"dev": "start http://localhost:3000 & node-dev app & grunt watch"
}

...and start the app using 'npm run dev' a new browser tab opens successfully and the app runs on port 3000 as expected, however 'grunt watch' does not run. I can open a new bash window and run 'grunt watch' separately and it works successfully. I can also automate opening the browser window and then running 'grunt watch' successfully, but it seems that I cannot start up the server AND run grunt from the same bash window - is this a known issue in Windows?

When chaining different command with & commands are executed one after the other. That mean that in your configuration the & node-dev app & grunt watch commands will be executed only once you close the server.

To execute different command in parallel in my build I use the parallelshell module... I'm not sure how stable it is though but it seems to work for me. There is probably other more suitable solution.

link to the npm page of parallelshell : https://www.npmjs.com/package/parallelshell

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM