The solution to this issue has been explained in other threads, see: How to compile scss to css with node-sass
However, here's my solution using the run-watch program, nodemon:
npm install node-sass nodemon --save-dev
In package.json, add these to your "scripts":
"build-css": "node-sass --include-path scss src/input.scss src/styles.css",
"watch-css": "nodemon -e scss -x \"npm run build-css\" "
Then, in your "start" script, use this:
"start": "concurrently \"node app.js\" \"npm run watch-css\" "
Next, we need to install the concurrently package:
npm install concurrently --save
To compile and serve your files,
npm start
Therefore, the "npm start" command triggers a build that starts the app and concurrently calls the "run watch-css" command which in turn calls "build-css" to compile scss to css in real-time through nodemon. It compiles and refreshes live when you edit any scss in your text editor.
Answer from anycoloryoulike84 on Stack Overflow
» npm install css-scss
The solution to this issue has been explained in other threads, see: How to compile scss to css with node-sass
However, here's my solution using the run-watch program, nodemon:
npm install node-sass nodemon --save-dev
In package.json, add these to your "scripts":
"build-css": "node-sass --include-path scss src/input.scss src/styles.css",
"watch-css": "nodemon -e scss -x \"npm run build-css\" "
Then, in your "start" script, use this:
"start": "concurrently \"node app.js\" \"npm run watch-css\" "
Next, we need to install the concurrently package:
npm install concurrently --save
To compile and serve your files,
npm start
Therefore, the "npm start" command triggers a build that starts the app and concurrently calls the "run watch-css" command which in turn calls "build-css" to compile scss to css in real-time through nodemon. It compiles and refreshes live when you edit any scss in your text editor.
Running gulp will run the default task which you haven't included in your gulpfile. You need to add this
gulp.task('default', ['sass','watch']);
Videos
» npm install gulp-css-scss
» npm install schematics-scss-migrate
» npm install css-to-scss
» npm install @adamlui/scss-to-css
I picked node-sass implementer for libsass because it is based on node.js.
Installing node-sass
- (Prerequisite) If you don't have npm, install Node.js first.
$ npm install -g node-sassinstalls node-sass globally-g.
This will hopefully install all you need, if not read libsass at the bottom.
How to use node-sass from Command line and npm scripts
General format:
$ node-sass [options] <input.scss> [output.css]
$ cat <input.scss> | node-sass > output.css
Examples:
$ node-sass my-styles.scss my-styles.csscompiles a single file manually.$ node-sass my-sass-folder/ -o my-css-folder/compiles all the files in a folder manually.$ node-sass -w sass/ -o css/compiles all the files in a folder automatically whenever the source file(s) are modified.-wadds a watch for changes to the file(s).
More usefull options like 'compression' @ here. Command line is good for a quick solution, however, you can use task runners like Grunt.js or Gulp.js to automate the build process.
You can also add the above examples to npm scripts. To properly use npm scripts as an alternative to gulp read this comprehensive article @ css-tricks.com especially read about grouping tasks.
- If there is no
package.jsonfile in your project directory running$ npm initwill create one. Use it with-yto skip the questions. - Add
"sass": "node-sass -w sass/ -o css/"toscriptsinpackage.jsonfile. It should look something like this:
"scripts": {
"test" : "bla bla bla",
"sass": "node-sass -w sass/ -o css/"
}
$ npm run sasswill compile your files.
How to use with gulp
$ npm install -g gulpinstalls Gulp globally.- If there is no
package.jsonfile in your project directory running$ npm initwill create one. Use it with-yto skip the questions. $ npm install --save-dev gulpinstalls Gulp locally.--save-devaddsgulptodevDependenciesinpackage.json.$ npm install gulp-sass --save-devinstalls gulp-sass locally.- Setup gulp for your project by creating a
gulpfile.jsfile in your project root folder with this content:
'use strict';
var gulp = require('gulp');
A basic example to transpile
Add this code to your gulpfile.js:
var gulp = require('gulp');
var sass = require('gulp-sass');
gulp.task('sass', function () {
gulp.src('./sass/**/*.scss')
.pipe(sass().on('error', sass.logError))
.pipe(gulp.dest('./css'));
});
$ gulp sass runs the above task which compiles .scss file(s) in the sass folder and generates .css file(s) in the css folder.
To make life easier, let's add a watch so we don't have to compile it manually. Add this code to your gulpfile.js:
gulp.task('sass:watch', function () {
gulp.watch('./sass/**/*.scss', ['sass']);
});
All is set now! Just run the watch task:
$ gulp sass:watch
How to use with Node.js
As the name of node-sass implies, you can write your own node.js scripts for transpiling. If you are curious, check out node-sass project page.
What about libsass?
Libsass is a library that needs to be built by an implementer such as sassC or in our case node-sass. Node-sass contains a built version of libsass which it uses by default. If the build file doesn't work on your machine, it tries to build libsass for your machine. This process requires Python 2.7.x (3.x doesn't work as of today). In addition:
LibSass requires GCC 4.6+ or Clang/LLVM. If your OS is older, this version may not compile. On Windows, you need MinGW with GCC 4.6+ or VS 2013 Update 4+. It is also possible to build LibSass with Clang/LLVM on Windows.
npx node-sass input.scss out.css
» npm install css-to-sass
» npm install compile-sass
» npm install create-scss
» npm install node-sass
» npm install @dhunanyan/scss-to-css-converter
» npm install node-scss