initCompiler

  • 相容性
    Dart Sass
    自 1.70.0 版本起
    Node Sass

    建立一個同步的編譯器。每個編譯器實例在編譯器的生命週期內公開 compilecompileString 方法。給定相同的輸入,這些方法將返回與模組根目錄公開的對應方法相同的結果。要使用非同步編譯,請使用 initAsyncCompiler

    當多次呼叫編譯函式時,使用帶有 sass-embedded npm 套件的編譯器實例比使用頂層編譯方法或 sass npm 套件快得多。

    範例

    const sass = require('sass');
    function setup() {
    const compiler = sass.initCompiler();
    const result1 = compiler.compileString('a {b: c}').css;
    const result2 = compiler.compileString('a {b: c}').css;
    compiler.dispose();

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

    返回 編譯器