內建插件
createEngine() 在附加任何來自 config.plugins 的使用者插件之前,始終會載入五個核心插件。
核心插件
五個內建插件以固定順序在 createEngine() 內部建立:
| 順序 | 插件名稱 | 設定鍵 | 用途 |
|---|---|---|---|
| 1 | core:important | important | 在 CSS 值後附加 !important |
| 2 | core:variables | variables | 帶有清除功能的 CSS 自訂屬性 |
| 3 | core:keyframes | keyframes | @keyframes 動畫管理 |
| 4 | core:selectors | selectors | 選擇器別名解析 |
| 5 | core:shortcuts | shortcuts | 可重複使用的樣式捷徑 |
插件載入與排序
建立核心插件並附加使用者插件後,所有插件會依其 order 屬性一起排序:
order 值 | 排序權重 | 執行時機 |
|---|---|---|
'pre' | 0 | 最先執行 |
undefined | 1 | 預設值(核心插件使用此值) |
'post' | 2 | 最後執行 |
ts
// Conceptual loading order inside createEngine():
//
// 1. Core plugins are created first:
// - core:important
// - core:variables
// - core:keyframes
// - core:selectors
// - core:shortcuts
//
// 2. User plugins from config.plugins are appended.
//
// 3. ALL plugins are sorted together by `order`:
// - order: 'pre' → 0 (runs first)
// - order: undefined → 1 (default — core plugins use this)
// - order: 'post' → 2 (runs last)
//
// 4. Hooks execute in the sorted order:
// configureRawConfig → rawConfigConfigured
// → resolveConfig
// → configureResolvedConfig → configureEngineWARNING
由於核心插件未設定 order(權重為 1),具有 order: 'pre' 的使用者插件會在核心插件之前執行。這對於在核心插件處理之前修改原始設定非常有用。
鉤子執行流程
所有插件(核心與使用者的)都參與同一個鉤子流程,依排序順序執行:
在執行階段,當樣式被處理時會觸發額外的鉤子:
transformSelectors— 解析選擇器別名transformStyleItems— 解析捷徑字串transformStyleDefinitions— 展開__important與__shortcutpreflightUpdated— 變數/關鍵影格已變更atomicStyleAdded— 新的原子化樣式已被註冊autocompleteConfigUpdated— 自動補齊中繼資料已變更
設定內建插件
你可透過 EngineConfig 的頂層鍵來設定內建插件,而非匯入內部工廠函式:
ts
import { defineEngineConfig } from '@pikacss/unplugin-pikacss'
export default defineEngineConfig({
important: { /* ... */ },
variables: { /* ... */ },
keyframes: { /* ... */ },
selectors: { /* ... */ },
shortcuts: { /* ... */ },
})插件詳細頁面
- Important —
!important管理 - Variables — CSS 自訂屬性
- Keyframes —
@keyframes動畫 - Selectors — 選擇器別名
- Shortcuts — 可重複使用的樣式捷徑
原始碼參考
packages/core/src/internal/engine.ts—createEngine()、插件連接packages/core/src/internal/plugin.ts—resolvePlugins()、鉤子執行packages/core/src/internal/plugins/— 各個插件實作