Node.js wrapper around libsass for compiling Sass and SCSS files to CSS
npx @tessl/cli install tessl/npm-node-sass@9.0.0node-sass is a Node.js wrapper around libsass, the C/C++ port of the popular Sass CSS preprocessor. It provides both programmatic APIs and command-line tools for compiling Sass and SCSS files into CSS, with support for source maps, custom functions, and various output styles.
npm install node-sassconst sass = require("node-sass");For ES modules:
import sass from "node-sass";const sass = require("node-sass");
// Compile from file
sass.render({
file: "input.scss",
outFile: "output.css",
}, (error, result) => {
if (error) {
console.error(error);
} else {
console.log(result.css.toString());
}
});
// Compile from string
sass.render({
data: "$primary-color: #333; body { color: $primary-color; }",
}, (error, result) => {
if (error) {
console.error(error);
} else {
console.log(result.css.toString());
}
});
// Synchronous compilation
try {
const result = sass.renderSync({
file: "input.scss"
});
console.log(result.css.toString());
} catch (error) {
console.error(error);
}node-sass is structured around several key components:
render) and synchronous (renderSync) compilation functionsPrimary Sass/SCSS compilation functionality for converting stylesheets to CSS with full configuration options.
function render(options, callback);
function renderSync(options);Complete type system for creating and manipulating Sass values in custom functions, including colors, numbers, strings, lists, and maps.
const types = {
Boolean: function(value),
Color: function(r, g, b, a),
Error: function(message),
List: function(length, separator),
Map: function(length),
Null: function(),
Number: function(value, unit),
String: function(value)
};Comprehensive CLI tool for build processes, file watching, and batch compilation with extensive configuration options.
node-sass [options] <input> [output]
node-sass --watch <input> --output <output>Utilities for managing platform-specific binaries, environment detection, and installation processes.
// Exposed through extensions module (internal)
function getBinaryPath();
function isSupportedEnvironment();
function getVersionInfo(binding);const TRUE = sass.TRUE; // Sass Boolean TRUE singleton
const FALSE = sass.FALSE; // Sass Boolean FALSE singleton
const NULL = sass.NULL; // Sass Null singleton
const info = sass.info; // Version information stringThese constants provide direct access to commonly used Sass singleton values:
sass.TRUE - Singleton instance representing Sass boolean true (same as sass.types.Boolean.TRUE)sass.FALSE - Singleton instance representing Sass boolean false (same as sass.types.Boolean.FALSE)sass.NULL - Singleton instance representing Sass null (same as sass.types.Null.NULL)sass.info - String containing version information for node-sass and libsass