Presets allow you to group rules, variants, and shortcuts into a reusable package that can be shared across projects or teams. This is ideal for implementing a company-wide design system.
// 1. Define the preset in a separate file (e.g., my-preset.ts)
import { Preset } from 'unocss'
export const myPreset: Preset = {
name: 'my-preset',
rules: [
[/^m-([.\d]+)$/, ([_, num]) => ({ margin: `${num}px` })],
[/^p-([.\d]+)$/, ([_, num]) => ({ padding: `${num}px` })],
],
variants: [],
shortcuts: [],
}
// 2. Register the preset in your config (uno.config.ts)
import { defineConfig } from 'unocss'
import { myPreset } from './my-preset'
export default defineConfig({
presets: [
myPreset,
],
})