Skip to content

预设

¥Presets

预设是部分配置,将合并到主配置中。

¥Presets are partial configurations that will be merged into the main configuration.

在创作预设时,我们通常会导出一个构造函数,你可以要求提供一些特定于预设的选项。例如:

¥When authoring a preset, we usually export a constructor function that you could ask for some preset-specific options. For example:

ts
// my-preset.ts
import { Preset, definePreset } 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
  }
})

然后用户可以像这样使用它:

¥Then the user can use it like this:

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

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

你可以查看 官方预设社区预设 以获取更多示例。

¥You can check official presets and community presets for more examples.