Here's how you can convert your SASS files or SCSS stylesheet to precompiled CSS stylesheet using nodeJS:
npm install -g sass
Open a new terminal in your favorite code editor, for example Visual Studio Code and run the command below
npm install -g sass
You need to import the package using const sass = require('sass');
You can use the below code snippet to transform an SCSS string to a CSS string
var result = sass.compileString(
"my SCSS string"
);
Example:
var result = sass.compileString(
`
$font-stack: Helvetica, sans-serif;
$primary-color: #333;
body {
font: 100% $font-stack;
color: $primary-color;
}
nav {
ul {
margin: 0;
padding: 0;
list-style: none;
}
}
`);
This is going to return the result below:
body {
font: 100% Helvetica, sans-serif;
color: #333;
}
nav ul {
margin: 0;
padding: 0;
list-style: none;
}
If you have a scss file, save the script in step 2 in the same directory as your scss file and run the below command:
var result = sass.compile("myscssfile.scss");
The tool will precompile your SCSS input into CSS format.