編譯

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

    同步編譯位於 path 的 Sass 檔案為 CSS。如果成功,則返回 CompileResult;如果失敗,則拋出 Exception。

    這僅允許同步 Importer 和 CustomFunction。

    ⚠️ 注意!

    使用 sass-embedded npm 套件進行單次編譯時,compileAsync 幾乎總是比 compile,這是因為使用 worker threads 模擬同步訊息傳遞的額外開銷,以及並行編譯會在主執行緒上被阻塞。

    如果您使用 sass-embedded npm 套件執行多次編譯,使用 Compiler 將會比模組層級的方法提供一些速度上的改進,而使用 AsyncCompiler 則會更快。

    範例

    const sass = require('sass');

    const result = sass.compile("style.scss");
    console.log(result.css);

    參數

    • path: string(字串)
    • 選用 options: Options<"sync">(選項)

    回傳 CompileResult(編譯結果)