initAsyncCompiler

  • initAsyncCompiler():Promise<AsyncCompiler>
  • Compatibility:
    Dart Sass
    since 1.70.0
    Node Sass

    Creates an asynchronousAsyncCompiler. Each compilerinstance exposes thecompileAsync andcompileStringAsyncmethods within the lifespan of the Compiler. Given identical input, thesemethods will return results identical to their counterparts exposed at themodule root. To use synchronous compilation, useinitCompiler;

    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');
    asyncfunctionsetup() {
    constcompiler =awaitsass.initAsyncCompiler();
    constresult1 =awaitcompiler.compileStringAsync('a {b: c}').css;
    constresult2 =awaitcompiler.compileStringAsync('a {b: c}').css;
    awaitcompiler.dispose();

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

    ReturnsPromise<AsyncCompiler>