LegacySyncFunction

LegacySyncFunction: ((this: LegacyPluginThis, args: LegacyValue[]) => LegacyValue) (舊版同步函式)

類型宣告(Type declaration)

    • (this: LegacyPluginThis, args: LegacyValue[]): LegacyValue
    • 一個同步回呼函式,用於實現自定義 Sass 函式。可以將其傳遞給 functions,以用於 renderrenderSync

      如果這個函式拋出錯誤,Sass 將會視為該函式執行失敗,並顯示錯誤訊息。

      const result = sass.renderSync({
      file: 'style.scss',
      functions: {
      "sum($arg1, $arg2)": (arg1, arg2) => {
      if (!(arg1 instanceof sass.types.Number)) {
      throw new Error("$arg1: Expected a number");
      } else if (!(arg2 instanceof sass.types.Number)) {
      throw new Error("$arg2: Expected a number");
      }
      return new sass.types.Number(arg1.getValue() + arg2.getValue());
      }
      }
      });

      已棄用(Deprecated)

      這僅適用於舊版 renderrenderSync API。請改用 CustomFunction 搭配 compilecompileStringcompileAsynccompileStringAsync

      參數

      回傳 LegacyValue