compileString

  • compileString(source:string,options?:StringOptions<"sync">):CompileResult
  • Compatibility:
    Dart Sass
    since 1.45.0
    Node Sass

    Synchronously compiles a stylesheet whose contents issource toCSS. If itsucceeds it returns aCompileResult, and if it fails it throws anException.

    This only allows synchronousImporters andCustomFunctions.

    ⚠️ Heads up!

    When using thesass-embedded npm package for singlecompilations,compileStringAsync is almost always faster thancompileString, due to the overhead of emulating synchronousmessaging with worker threads and concurrent compilations being blocked onmain thread.

    If you are running multiple compilations with thesass-embedded npmpackage, using aCompiler will provide some speed improvements overthe module-level methods, and anAsyncCompiler will be much faster.

    Example

    constsass =require('sass');

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

    Parameters

    ReturnsCompileResult