conor909
conor909

Reputation: 1623

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"

Upvotes: 6

Views: 8848

Answers (2)

PRIS54
PRIS54

Reputation: 21

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

Upvotes: 2

Robbie
Robbie

Reputation: 19510

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.

Upvotes: 4

Related Questions