sass

Both Dart Sass and LibSass support the same JavaScript API. Dart Sass is distributed as the pure-Javascript sass package, and LibSass is distributed as a native extension in the node-sass package.

Usage

The JavaScript API has two entrypoints for compiling Sass to CSS. Each one can compile either a Sass file by passing in LegacyFileOptions or a string of Sass code by passing in a LegacyStringOptions.

  • renderSync runs synchronously. It's by far the fastest option when using Dart Sass, but at the cost of only supporting synchronous importer and function plugins.

    const sass = require('sass'); // or require('node-sass');

    const result = sass.renderSync({file: "style.scss"});
    console.log(result.css.toString());
  • render runs asynchronously and calls a callback when it finishes. It's much slower when using Dart Sass, but it supports asynchronous importer and function plugins.

    const sass = require('sass'); // or require('node-sass');

    sass.render({
    file: "style.scss"
    }, function(err, result) {
    if (err) {
    // ...
    } else {
    console.log(result.css.toString());
    }
    });

Integrations

Most popular Node.js build systems have integrations available for the JS API: