An example app using the node-sass npm module to compile .scss to CSS. I am using Hapi to create a simple server serving a static file, but the approach below will work with other frameworks or indeed no frameworks.
npm install -g nodemon
npm install node-sass
In the scripts section of package.json:
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build-css": "node-sass --include-path scss sass/main.scss public/css/main.css",
"watch-css": "nodemon -e scss -x \"npm run build-css\"",
"devstart": "nodemon server.js"
}
build-css
: Uses node-sass to compile .scss to css (in specified paths).
watch-css
: Uses nodemon to watch for changes to scss files and run build-css
when changes are made.
devstart
: Starts the server, watching for changes and restarting the server when changes are made.
git clone https://github.com/mantagen/node-sass-example
npm install
In one terminal:
npm run watch-css
In another terminal:
npm run devstart