Search code examples
node.jsnpmpostcss

How to watch .sss files and re-run my npm script if they change


Is there a way to watch my .sss files and re-run this if they change?

"css": "postcss -u autoprefixer -u postcss-easy-import -p sugarss src/index.sss -o src/index.css"

I can't find a way, I've looked on the net all over. I don't see any kind of watch available from postcss. There's a -w or --watch with the postcss-cli but I tried adding that to the end of the script above. Unless I'm just doing it wrong, my css script does not re-run itself if my .sss files change.

maybe there's some generic node watcher lib I can use?


Solution

  • nodemon is a very powerful tool to re-run your scripts based on any change in your files , default file extension for nodemon to watch is .js and default script to run from your package.json file is start script.

    You can overwrite watched extension using -e option , then extensions separated by , for example -e sss in your case.

    Also you can overwrite the script you want to run using --exec option and then pass the script you want to run , in your case it will be --exec "npm run css"

    And put all together nodemon -e sss --exec "npm run css" , this will watch changes in sss files and run css script