initAsyncCompiler

  • Compatibility:
    Dart Sass
    since 1.70.0
    Node Sass

    Creates an asynchronous AsyncCompiler. Each compiler instance exposes the compileAsync and compileStringAsync 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 synchronous compilation, use initCompiler;

    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');
    async function setup() {
    const compiler = await sass.initAsyncCompiler();
    const result1 = await compiler.compileStringAsync('a {b: c}').css;
    const result2 = await compiler.compileStringAsync('a {b: c}').css;
    await compiler.dispose();

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

    Returns Promise<AsyncCompiler>