You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -8,51 +8,210 @@ A DevTools plugin is a **superset** of a Vite plugin—meaning any Vite plugin c
8
8
9
9
## Installation
10
10
11
-
To get started, install the `@vitejs/devtools-kit` package in your Vite plugin project. It's typically fine to add it as a dev dependency since we only need it for types on the Node.js side.
11
+
Install the `@vitejs/devtools-kit` package in your Vite plugin project:
12
12
13
-
```zsh
14
-
pnpm install -D @vitejs/devtools-kit
13
+
::: code-group
14
+
15
+
```bash [pnpm]
16
+
pnpm add -D @vitejs/devtools-kit
17
+
```
18
+
19
+
```bash [npm]
20
+
npm install -D @vitejs/devtools-kit
15
21
```
16
22
17
-
Then referencing it in your plugin code, it will augment the `Plugin` interface with the `devtools` property.
23
+
```bash [yarn]
24
+
yarn add -D @vitejs/devtools-kit
25
+
```
26
+
27
+
:::
28
+
29
+
> [!NOTE]
30
+
> It's typically fine to add it as a dev dependency since we only need it for types on the Node.js side.
31
+
32
+
## Basic Setup
18
33
19
-
Inside `devtools.setup`, you will get tools to register custom data visualization, actions, and more. See the sections below for details on [registering dock entries](./dock-system), and [RPC functions](./rpc).
34
+
Add the triple-slash reference to augment Vite's `Plugin` interface with the `devtools` property:
20
35
21
-
```ts {1,9-14}
36
+
```ts
22
37
/// <referencetypes="@vitejs/devtools-kit" />
23
-
import { Plugin } from'vite'
38
+
importtype{ Plugin } from'vite'
24
39
25
40
exportdefaultfunction myPlugin():Plugin {
26
41
return {
27
42
name: 'my-plugin',
28
-
// Do other plugin stuff...
29
-
transform(code, id) {},
30
-
// Devtools setup
43
+
44
+
// Regular Vite plugin hooks
45
+
configResolved(config) {
46
+
// ...
47
+
},
48
+
49
+
// DevTools setup - only called when DevTools is enabled
31
50
devtools: {
32
51
setup(ctx) {
33
-
console.log('My plugin setup')
52
+
console.log('DevTools setup for my-plugin')
53
+
54
+
// Register dock entries, RPC functions, etc.
55
+
ctx.docks.register({
56
+
id: 'my-plugin',
57
+
title: 'My Plugin',
58
+
icon: 'ph:puzzle-piece-duotone',
59
+
type: 'iframe',
60
+
url: '/.my-plugin/',
61
+
})
34
62
},
35
63
},
36
64
}
37
65
}
38
66
```
39
67
40
-
When users run their app with Vite DevTools enabled (`vite dev --ui`), your devtools setup function will be called.
68
+
> [!TIP] When is `setup` called?
69
+
> The `devtools.setup` function is called when users run their app with Vite DevTools enabled via `vite dev --ui` or `vite build --ui` (not implemented in Vite yet). It runs once during Vite server initialization.
41
70
42
71
## DevTools Context
43
72
44
-
The `setup` function receives a `DevToolsNodeContext` which provides access to:
73
+
The `setup` function receives a `DevToolsNodeContext` object that provides access to all DevTools APIs:
74
+
75
+
```ts
76
+
const plugin:Plugin= {
77
+
devtools: {
78
+
setup(ctx) {
79
+
// ctx contains everything you need
80
+
}
81
+
}
82
+
}
83
+
```
84
+
85
+
### Available Properties
86
+
87
+
| Property | Type | Description |
88
+
|----------|------|-------------|
89
+
|`ctx.docks`|`DocksHost`| Register and manage [dock entries](./dock-system)|
90
+
|`ctx.views`|`ViewsHost`| Host static files for your DevTools UI |
91
+
|`ctx.rpc`|`RpcHost`| Register [RPC functions](./rpc) and broadcast to clients |
92
+
|`ctx.viteConfig`|`ResolvedConfig`| The resolved Vite configuration |
93
+
|`ctx.viteServer`|`ViteDevServer \| undefined`| Vite dev server instance (only in dev mode) |
0 commit comments