Skip to content

Commit ea89cc4

Browse files
antfuclaude
andcommitted
docs: update Vite DevTools Kit skills with recent features
Add comprehensive documentation for: - Logs & notifications system (fire-and-forget, handles, deduplication, toasts) - Launcher dock entry type (setup cards for initialization) - Self-Inspect debugging plugin (@vitejs/devtools-self-inspect) - Updated field name reference (source → from) in docs - Launcher usage in dock-entry-types.md and badge property - Setup-time shared state initialization - Example plugin references for agents and developers Also create new logs-patterns.md reference file with complete patterns and examples. Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
1 parent 036aff0 commit ea89cc4

File tree

6 files changed

+372
-7
lines changed

6 files changed

+372
-7
lines changed

docs/kit/logs.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ The Logs system allows plugins to emit structured log entries from both the serv
2727
| `status` | `'loading' \| 'idle'` | No | Status indicator (shows spinner when `'loading'`) |
2828
| `id` | `string` | No | Explicit id for deduplication — re-adding with the same id updates the existing entry |
2929

30-
The `source` field is automatically set to `'server'` or `'client'` depending on where the log was emitted.
30+
The `from` field is automatically set to `'server'` or `'browser'` depending on where the log was emitted.
3131

3232
## Usage
3333

skills/vite-devtools-kit/SKILL.md

Lines changed: 115 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ name: writing-vite-devtools-integrations
33
description: >
44
Creates devtools integrations for Vite using @vitejs/devtools-kit.
55
Use when building Vite plugins with devtools panels, RPC functions,
6-
dock entries, shared state, or any devtools-related functionality.
7-
Applies to files importing from @vitejs/devtools-kit or containing
8-
devtools.setup hooks in Vite plugins.
6+
dock entries, shared state, logs/notifications, or any devtools-related
7+
functionality. Applies to files importing from @vitejs/devtools-kit or
8+
containing devtools.setup hooks in Vite plugins.
99
---
1010

1111
# Vite DevTools Kit
@@ -18,10 +18,11 @@ A DevTools plugin extends a Vite plugin with a `devtools.setup(ctx)` hook. The c
1818

1919
| Property | Purpose |
2020
|----------|---------|
21-
| `ctx.docks` | Register dock entries (iframe, action, custom-render) |
21+
| `ctx.docks` | Register dock entries (iframe, action, custom-render, launcher) |
2222
| `ctx.views` | Host static files for UI |
2323
| `ctx.rpc` | Register RPC functions, broadcast to clients |
2424
| `ctx.rpc.sharedState` | Synchronized server-client state |
25+
| `ctx.logs` | Emit structured log entries and toast notifications |
2526
| `ctx.viteConfig` | Resolved Vite configuration |
2627
| `ctx.viteServer` | Dev server instance (dev mode only) |
2728
| `ctx.mode` | `'dev'` or `'build'` |
@@ -123,6 +124,7 @@ export default function myAnalyzer(): Plugin {
123124
| `iframe` | Full UI panels, dashboards (most common) |
124125
| `action` | Buttons that trigger client-side scripts (inspectors, toggles) |
125126
| `custom-render` | Direct DOM access in panel (framework mounting) |
127+
| `launcher` | Actionable setup cards for initialization tasks |
126128

127129
### Iframe Entry
128130

@@ -166,6 +168,89 @@ ctx.docks.register({
166168
})
167169
```
168170

171+
### Launcher Entry
172+
173+
```ts
174+
const entry = ctx.docks.register({
175+
id: 'my-setup',
176+
title: 'My Setup',
177+
icon: 'ph:rocket-launch-duotone',
178+
type: 'launcher',
179+
launcher: {
180+
title: 'Initialize My Plugin',
181+
description: 'Run initial setup before using the plugin',
182+
buttonStart: 'Start Setup',
183+
buttonLoading: 'Setting up...',
184+
onLaunch: async () => {
185+
// Run initialization logic
186+
},
187+
},
188+
})
189+
```
190+
191+
## Logs & Notifications
192+
193+
Plugins can emit structured log entries from both server and client contexts. Logs appear in the built-in **Logs** panel and can optionally show as toast notifications.
194+
195+
### Fire-and-Forget
196+
197+
```ts
198+
// No await needed
199+
context.logs.add({
200+
message: 'Plugin initialized',
201+
level: 'info',
202+
})
203+
```
204+
205+
### With Handle
206+
207+
```ts
208+
const handle = await context.logs.add({
209+
id: 'my-build',
210+
message: 'Building...',
211+
level: 'info',
212+
status: 'loading',
213+
})
214+
215+
// Update later
216+
await handle.update({
217+
message: 'Build complete',
218+
level: 'success',
219+
status: 'idle',
220+
})
221+
222+
// Or dismiss
223+
await handle.dismiss()
224+
```
225+
226+
### Key Fields
227+
228+
| Field | Type | Description |
229+
|-------|------|-------------|
230+
| `message` | `string` | Short title (required) |
231+
| `level` | `'info' \| 'warn' \| 'error' \| 'success' \| 'debug'` | Severity (required) |
232+
| `description` | `string` | Detailed description |
233+
| `notify` | `boolean` | Show as toast notification |
234+
| `filePosition` | `{ file, line?, column? }` | Source file location (clickable) |
235+
| `elementPosition` | `{ selector?, boundingBox?, description? }` | DOM element position |
236+
| `id` | `string` | Explicit id for deduplication |
237+
| `status` | `'loading' \| 'idle'` | Shows spinner when loading |
238+
| `category` | `string` | Grouping (e.g., `'a11y'`, `'lint'`) |
239+
| `labels` | `string[]` | Tags for filtering |
240+
| `autoDismiss` | `number` | Toast auto-dismiss time in ms (default: 5000) |
241+
| `autoDelete` | `number` | Auto-delete time in ms |
242+
243+
The `from` field is automatically set to `'server'` or `'browser'`.
244+
245+
### Deduplication
246+
247+
Re-adding with the same `id` updates the existing entry instead of creating a duplicate:
248+
249+
```ts
250+
context.logs.add({ id: 'my-scan', message: 'Scanning...', level: 'info', status: 'loading' })
251+
context.logs.add({ id: 'my-scan', message: 'Scan complete', level: 'success', status: 'idle' })
252+
```
253+
169254
## RPC Functions
170255

171256
### Server-Side Definition
@@ -308,6 +393,22 @@ Export from package.json:
308393
}
309394
```
310395

396+
## Debugging with Self-Inspect
397+
398+
Use `@vitejs/devtools-self-inspect` to debug your DevTools plugin. It shows registered RPC functions, dock entries, client scripts, and plugins in a meta-introspection UI at `/.devtools-self-inspect/`.
399+
400+
```ts
401+
import DevTools from '@vitejs/devtools'
402+
import DevToolsSelfInspect from '@vitejs/devtools-self-inspect'
403+
404+
export default defineConfig({
405+
plugins: [
406+
DevTools(),
407+
DevToolsSelfInspect(),
408+
],
409+
})
410+
```
411+
311412
## Best Practices
312413

313414
1. **Always namespace** - Prefix all identifiers with your plugin name
@@ -316,10 +417,20 @@ Export from package.json:
316417
4. **Batch mutations** - Use single `mutate()` call for multiple changes
317418
5. **Host static files** - Use `ctx.views.hostStatic()` for your UI assets
318419
6. **Use Iconify icons** - Prefer `ph:*` (Phosphor) icons: `icon: 'ph:chart-bar-duotone'`
420+
7. **Deduplicate logs** - Use explicit `id` for logs representing ongoing operations
421+
8. **Use Self-Inspect** - Add `@vitejs/devtools-self-inspect` during development to debug your plugin
422+
423+
## Example Plugins
424+
425+
Real-world example plugins in the repo — reference their code structure and patterns when building new integrations:
426+
427+
- **A11y Checker** ([`examples/plugin-a11y-checker`](https://github.com/vitejs/devtools/tree/main/examples/plugin-a11y-checker)) — Action dock entry, client-side axe-core audits, logs with severity levels and element positions, log handle updates
428+
- **File Explorer** ([`examples/plugin-file-explorer`](https://github.com/vitejs/devtools/tree/main/examples/plugin-file-explorer)) — Iframe dock entry, RPC functions (static/query/action), hosted UI panel, RPC dump for static builds, backend mode detection
319429

320430
## Further Reading
321431

322432
- [RPC Patterns](./references/rpc-patterns.md) - Advanced RPC patterns and type utilities
323433
- [Dock Entry Types](./references/dock-entry-types.md) - Detailed dock configuration options
324434
- [Shared State Patterns](./references/shared-state-patterns.md) - Framework integration examples
325435
- [Project Structure](./references/project-structure.md) - Recommended file organization
436+
- [Logs Patterns](./references/logs-patterns.md) - Log entries, toast notifications, and handle patterns

skills/vite-devtools-kit/references/dock-entry-types.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ interface DockEntryBase {
1414
category?: string // Grouping category
1515
defaultOrder?: number // Sort order (higher = earlier)
1616
isHidden?: boolean // Hide from dock
17+
badge?: string // Badge text on dock icon (e.g., count)
1718
}
1819
```
1920

@@ -200,6 +201,60 @@ export default function setup(ctx: DevToolsClientScriptContext) {
200201
}
201202
```
202203

204+
## Launcher Entries
205+
206+
Actionable setup cards for running initialization tasks. Shows a card with title, description, and a launch button.
207+
208+
```ts
209+
type LauncherStatus = 'idle' | 'loading' | 'success' | 'error'
210+
211+
interface LauncherEntry extends DockEntryBase {
212+
type: 'launcher'
213+
launcher: {
214+
title: string // Card title
215+
description?: string // Card description
216+
icon?: string | { light: string, dark: string } // Card icon
217+
buttonStart?: string // Start button text
218+
buttonLoading?: string // Loading button text
219+
status?: LauncherStatus // Current status
220+
error?: string // Error message when status is 'error'
221+
onLaunch: () => Promise<void> // Callback when user clicks launch
222+
}
223+
}
224+
225+
// Registration
226+
const entry = ctx.docks.register({
227+
id: 'my-setup',
228+
title: 'My Setup',
229+
icon: 'ph:rocket-launch-duotone',
230+
type: 'launcher',
231+
launcher: {
232+
title: 'Initialize My Plugin',
233+
description: 'Run the initial setup before the plugin can be used',
234+
buttonStart: 'Start Setup',
235+
buttonLoading: 'Setting up...',
236+
onLaunch: async () => {
237+
// Perform initialization
238+
await runSetup()
239+
},
240+
},
241+
})
242+
243+
// Update status after launch completes
244+
entry.update({
245+
launcher: {
246+
...entry.launcher,
247+
status: 'success',
248+
},
249+
})
250+
```
251+
252+
### Launcher Use Cases
253+
254+
- **First-run setup** — Run initial scans or configuration before showing results
255+
- **Build triggers** — Start a build or analysis pass on demand
256+
- **Authentication** — Prompt user to connect external services
257+
203258
## Client Script Events
204259

205260
| Event | Payload | Description |

0 commit comments

Comments
 (0)