initCompiler

  • initCompiler():Compiler
  • Compatibility:
    Dart Sass
    since 1.70.0
    Node Sass

    Creates a synchronousCompiler. Each compiler instance exposes thecompile andcompileString methods within the lifespan of theCompiler. Given identical input, these methods will return results identicalto their counterparts exposed at the module root. To use asynchronouscompilation, useinitAsyncCompiler.

    When calling the compile functions multiple times, using a compiler instancewith thesass-embedded npm package is much faster than using the top-levelcompilation methods or thesass npm package.

    Example

    constsass =require('sass');
    functionsetup() {
    constcompiler =sass.initCompiler();
    constresult1 =compiler.compileString('a {b: c}').css;
    constresult2 =compiler.compileString('a {b: c}').css;
    compiler.dispose();

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

    ReturnsCompiler