跳至內容

預設集

預設集是部分設定,將會合併到主要設定中。

在撰寫預設集時,我們通常會匯出一個建構函式,您可以要求一些預設集特定的選項。例如:

my-preset.ts
ts
import { definePreset, Preset } from 'unocss'

export default definePreset((options?: MyPresetOptions) => {
  return {
    name: 'my-preset',
    rules: [
      // ...
    ],
    variants: [
      // ...
    ],
    // it supports most of the configuration you could have in the root config
  }
})

然後使用者可以像這樣使用它:

uno.config.ts
ts
import { defineConfig } from 'unocss'
import myPreset from './my-preset'

export default defineConfig({
  presets: [
    myPreset({ /* preset options */ }),
  ],
})

您可以查看官方預設集社群預設集以獲得更多範例。

依 MIT 許可證發布。