Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

npm scripts nodemon - watching js and scss files for changes

I'm experimenting with setting up a dev environment to use NPM only, without the use of grunt.js or bower.js.

I followed this tutorial: http://beletsky.net/2015/04/npm-for-everything.html

I'm using nodemon to watch my .js and .scss files for changes which restarts the node server. So in my package.json file, under scripts I have

scripts:

"watch-js": "nodemon -e js --watch public/js -x \"npm run build-js\"",

"watch-sass": "nodemon -e scss --watch public/sass -x \"npm run build-sass\"",

"watch": "npm run watch-js & npm run watch-sass"

But when I run npm run watch it only watches for the public/js files to change. And it triggers a build accordingly.

But it won't watch for the sass files.

Versions: node v0.10.36 nodemon v1.4.1

I also include a build script which if I run compiles the sass to css, so my build-sass script should be ok

"build": "npm run build-js & npm run build-sass",
"watch": "npm run watch-js & npm run watch-sass"
like image 991
conor909 Avatar asked Aug 20 '15 20:08

conor909


2 Answers

If you are using windows, you might be encountering the windows problem

Because npm is reliant on the operating systems shell to run scripts commands, they can quickly become unportable. While Linux, Solaris, BSD and Mac OSX come preinstalled with Bash as the default shell, Windows does not. On Windows, npm will resort to using Windows command prompt for these things

If so, you can try using parallelshell or npm-run-all for better cross platform support.

like image 197
Robbie Avatar answered Oct 23 '22 03:10

Robbie


This works for me in Mac OS

  1. Install nodemon

    npm install --save-dev nodemon

  2. Install npm-run-all:

    npm install --save-dev npm-run-all

  3. In package.json add two scripts:

    "startn": "nodemon ./app.js", "watch-jscss": "gulp watch"

    • Where 'app.js' is your server file
    • "gulp watch" can be replace by whatever task is doing a sass watch
  4. In the console:

    npm-run-all --parallel watch-jscss startn

like image 25
PRIS54 Avatar answered Oct 23 '22 05:10

PRIS54