Available Hooks
PikaCSS plugins can implement hooks that run at specific points in the engine lifecycle.
configureRawConfig
Signature
configureRawConfig?: (config: EngineConfig) => void | EngineConfig | Promise<void | EngineConfig>When
Called during createEngine() before the raw config is resolved into its final form. Plugins can mutate the config object in-place or return a new one.
Example
defineEnginePlugin({
name: 'add-layer',
configureRawConfig: (config) => {
config.layers ??= {}
config.layers['my-layer'] = 5
},
})rawConfigConfigured
Signature
rawConfigConfigured?: (config: EngineConfig) => voidWhen
Called after configureRawConfig has run for all plugins. The raw config is finalized — this is a notification hook for reading the final raw config, not for mutation.
Example
defineEnginePlugin({
name: 'log-config',
rawConfigConfigured: (config) => {
console.log('Final raw config:', config)
},
})configureResolvedConfig
Signature
configureResolvedConfig?: (config: ResolvedEngineConfig) => void | ResolvedEngineConfig | Promise<void | ResolvedEngineConfig>When
Called after the raw config is resolved into a ResolvedEngineConfig. Plugins can adjust resolved values like prefix, layers, or autocomplete state.
Example
defineEnginePlugin({
name: 'override-prefix',
configureResolvedConfig: (config) => {
config.prefix = 'custom-'
},
})configureEngine
Signature
configureEngine?: (engine: Engine) => void | Engine | Promise<void | Engine>When
Called after the engine instance is constructed. Plugins can add preflights, register autocomplete entries, or extend the engine with custom behavior.
Example
defineEnginePlugin({
name: 'add-preflight',
configureEngine: async (engine) => {
engine.addPreflight({
layer: 'base',
preflight: '*, *::before, *::after { box-sizing: border-box; }',
})
},
})transformSelectors
Signature
transformSelectors?: (selectors: string[]) => string[] | Promise<string[]>When
Called when selector strings are being resolved during style extraction. Plugins can rewrite, expand, or filter selector values.
Example
defineEnginePlugin({
name: 'dark-mode',
transformSelectors: (selectors) => {
return selectors.map(s =>
s === '@dark' ? 'html.dark $' : s
)
},
})transformStyleItems
Signature
transformStyleItems?: (items: InternalStyleItem[]) => InternalStyleItem[] | Promise<InternalStyleItem[]>When
Called when style items are being processed in engine.use(). Plugins can inject, remove, or rewrite style items before they are extracted into atomic styles.
Example
defineEnginePlugin({
name: 'expand-shortcut',
transformStyleItems: (items) => {
return items.flatMap(item =>
item === 'my-shortcut'
? [{ display: 'flex' }, { alignItems: 'center' }]
: [item]
)
},
})transformStyleDefinitions
Signature
transformStyleDefinitions?: (definitions: InternalStyleDefinition[]) => InternalStyleDefinition[] | Promise<InternalStyleDefinition[]>When
Called after style items are converted to style definitions. Plugins can transform definitions before they are extracted into atomic CSS contents.
Example
defineEnginePlugin({
name: 'auto-prefix',
transformStyleDefinitions: (definitions) => {
return definitions
},
})preflightUpdated
Signature
preflightUpdated?: () => voidWhen
Called whenever a preflight is added or CSS imports change. Use this hook to react to preflight changes.
Example
defineEnginePlugin({
name: 'preflight-watcher',
preflightUpdated: () => {
console.log('Preflights changed')
},
})atomicStyleAdded
Signature
atomicStyleAdded?: (atomicStyle: AtomicStyle) => voidWhen
Called each time a new atomic style is registered in the engine store. Use this for tracking, analysis, or side effects.
Example
defineEnginePlugin({
name: 'style-tracker',
atomicStyleAdded: (atomicStyle) => {
console.log(`New style: ${atomicStyle.id}`)
},
})autocompleteConfigUpdated
Signature
autocompleteConfigUpdated?: () => voidWhen
Called whenever the autocomplete configuration changes. Use this to react to new autocomplete entries.
Example
defineEnginePlugin({
name: 'autocomplete-watcher',
autocompleteConfigUpdated: () => {
console.log('Autocomplete updated')
},
})Next
- Type Augmentation — extend PikaCSS types.
- Create a Plugin — plugin structure and the defineEnginePlugin helper.
- Define Helpers — identity helpers for type inference.