Skip to content

Commit cfdce12

Browse files
authored
docs: add examples page and feature links (#197)
1 parent aee6d0f commit cfdce12

File tree

6 files changed

+75
-0
lines changed

6 files changed

+75
-0
lines changed

docs/.vitepress/config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const DevToolsKitNav = [
1515
{ text: 'RPC', link: '/kit/rpc' },
1616
{ text: 'Shared State', link: '/kit/shared-state' },
1717
{ text: 'Logs & Notifications', link: '/kit/logs' },
18+
{ text: 'Examples', link: '/kit/examples' },
1819
]
1920

2021
const SocialLinks = [
@@ -68,6 +69,7 @@ export default extendConfig(withMermaid(defineConfig({
6869
{ text: 'RPC', link: '/kit/rpc' },
6970
{ text: 'Shared State', link: '/kit/shared-state' },
7071
{ text: 'Logs', link: '/kit/logs' },
72+
{ text: 'Examples', link: '/kit/examples' },
7173
],
7274
},
7375
],

docs/kit/dock-system.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@ icon: 'mdi:view-dashboard' // Material Design Icons
109109
> [!TIP]
110110
> Browse available icons at [Iconify](https://icon-sets.iconify.design/). The `ph:` (Phosphor) icon set works well for DevTools UIs.
111111
112+
> [!TIP]
113+
> See the [File Explorer example](/kit/examples#file-explorer) for a iframe dock plugin with RPC and static build support.
114+
112115
## Action Buttons
113116

114117
Action buttons run client-side scripts when clicked. They're perfect for:
@@ -196,6 +199,9 @@ Export the action script from your package:
196199
| `entry:activated` | Fired when the user clicks/activates this dock entry |
197200
| `entry:deactivated` | Fired when another entry is selected or the dock is closed |
198201

202+
> [!TIP]
203+
> See the [A11y Checker example](/kit/examples#a11y-checker) for a real-world action dock that runs axe-core audits and reports violations as logs.
204+
199205
## Custom Renderers
200206

201207
Custom renderers let you render directly into the DevTools panel DOM. This gives you full control and is useful when:

docs/kit/examples.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
---
2+
outline: deep
3+
---
4+
5+
# Examples
6+
7+
A collection of example plugins built with `@vitejs/devtools-kit` that demonstrate different features and patterns.
8+
9+
## A11y Checker
10+
11+
An accessibility auditing plugin powered by [axe-core](https://github.com/dequelabs/axe-core).
12+
13+
**Features demonstrated:**
14+
15+
- Registering an `action` dock entry with a client-side script
16+
- Running axe-core accessibility audits on the current page
17+
- Reporting violations as DevTools logs with severity levels
18+
- Using log handles to update a summary log in-place
19+
20+
**Source:** [`examples/plugin-a11y-checker`](https://github.com/vitejs/devtools/tree/main/examples/plugin-a11y-checker)
21+
22+
## File Explorer
23+
24+
A file explorer dock that lists, reads, and writes files through RPC.
25+
26+
**Features demonstrated:**
27+
28+
- Creating and registering RPC functions (`static`, `query`, `action`)
29+
- Hosting a custom UI panel with `context.views.hostStatic(...)`
30+
- Registering an `iframe` dock entry
31+
- RPC dump support for static builds
32+
- Detecting backend mode (`websocket` vs `static`) on the client
33+
34+
**Source:** [`examples/plugin-file-explorer`](https://github.com/vitejs/devtools/tree/main/examples/plugin-file-explorer)

docs/kit/logs.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,9 @@ context.logs.clear()
163163

164164
Logs have a maximum capacity of 1000 entries. When the limit is reached, the oldest entries are automatically removed.
165165

166+
> [!TIP]
167+
> See the [A11y Checker example](/kit/examples#a11y-checker) for a plugin that uses logs to report accessibility violations with severity levels, element positions, and WCAG labels.
168+
166169
## Dock Badge
167170

168171
The Logs dock icon automatically shows a badge with the total log count. The icon is hidden when there are no logs.

docs/kit/rpc.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,9 @@ export const readFile = defineRpcFunction({
315315
})
316316
```
317317

318+
> [!TIP]
319+
> See the [File Explorer example](/kit/examples#file-explorer) for a plugin using RPC functions with dump support, organized following the conventions above.
320+
318321
## Schema Validation (Optional)
319322

320323
The RPC system has built-in support for runtime schema validation using [Valibot](https://valibot.dev). When you provide schemas, TypeScript types are automatically inferred and validation happens at runtime.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Example: DevTools Kit A11y Checker Plugin
2+
3+
This example shows how to build an accessibility auditing plugin with `@vitejs/devtools-kit` and [axe-core](https://github.com/dequelabs/axe-core).
4+
5+
It registers an **action dock** that runs an axe-core audit on the current page and reports violations as DevTools logs.
6+
7+
## How It Works
8+
9+
1. Node plugin (`src/node/plugin.ts`)
10+
- registers an `action` dock entry that points to a client-side script
11+
- sends a startup log via `context.logs.add(...)`
12+
13+
2. Client script (`src/client/run-axe.ts`)
14+
- runs `axe.run(document)` when the dock action is triggered
15+
- maps each violation to a DevTools log with level based on impact (`critical`/`serious` → error, `moderate` → warn, `minor` → info)
16+
- attaches WCAG tags and element selectors to each log entry
17+
- updates a summary log with the total violation/pass count
18+
19+
## Run The Example
20+
21+
From the `examples/plugin-a11y-checker` directory (`cd examples/plugin-a11y-checker`):
22+
23+
```bash
24+
pnpm play:dev
25+
```
26+
27+
Then open the app URL, open Vite DevTools, and click the **Run A11y Check** action.

0 commit comments

Comments
 (0)