主题
预设
¥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
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
}
})
然后用户可以像这样使用它:
¥Then the user can use it like this:
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.