W3cubDocs

/Sass

compileStringAsync

  • Compatibility:
    Dart Sass
    since 1.45.0
    Node Sass

    Asynchronously compiles a stylesheet whose contents is source to CSS. Returns a promise that resolves with a CompileResult if it succeeds and rejects with an Exception if it fails.

    This only allows synchronous or asynchronous Importers and CustomFunctions.

    When using the sass npm package, compileString is almost twice as fast as compileStringAsync, due to the overhead of making the entire evaluation process asynchronous.

    Example

    constsass = require('sass');

    constresult = awaitsass.compileStringAsync(`
    h1 {
    font-size: 40px;
    code {
    font-face: Roboto Mono;
    }
    }`);
    console.log(result.css);

    Parameters

    Returns Promise<CompileResult>

© 2006–2025 the Sass team, and numerous contributors
Licensed under the MIT License.
https://sass-lang.com/documentation/js-api/functions/compileStringAsync