initCompiler

  • Compatibility:
    Dart Sass
    since 1.70.0
    Node Sass

    Creates a synchronous Compiler. Each compiler instance exposes the compile and compileString methods within the lifespan of the Compiler. Given identical input, these methods will return results identical to their counterparts exposed at the module root. To use asynchronous compilation, use initAsyncCompiler.

    When calling the compile functions multiple times, using a compiler instance with the sass-embedded npm package is much faster than using the top-level compilation methods or the sass npm package.

    Example

    const sass = require('sass');
    function setup() {
    const compiler = sass.initCompiler();
    const result1 = compiler.compileString('a {b: c}').css;
    const result2 = compiler.compileString('a {b: c}').css;
    compiler.dispose();

    // throws error
    const result3 = sass.compileString('a {b: c}').css;
    }

    Returns Compiler