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
Register your RPC function in the `devtools.setup`:
49
+
Recommended RPC function naming:
50
50
51
-
```ts
52
-
const plugin:Plugin= {
53
-
devtools: {
54
-
setup(ctx) {
55
-
ctx.rpc.register(getModules)
56
-
}
57
-
}
58
-
}
59
-
```
51
+
1. Scope functions with your package prefix: `<package-name>:...`
52
+
2. Use kebab-case for the function part after `:`
53
+
54
+
Examples:
55
+
-`my-plugin:get-modules`
56
+
-`my-plugin:read-file`
60
57
61
58
### Function Types
62
59
@@ -108,16 +105,33 @@ setup: (ctx) => {
108
105
> [!IMPORTANT]
109
106
> For build mode compatibility, compute data in the setup function using the context rather than relying on runtime global state. This allows the dump feature to pre-compute results at build time.
110
107
108
+
### Registering Functions
109
+
110
+
Register your RPC function in the `devtools.setup`:
111
+
112
+
```ts
113
+
const plugin:Plugin= {
114
+
devtools: {
115
+
setup(ctx) {
116
+
ctx.rpc.register(getModules)
117
+
}
118
+
}
119
+
}
120
+
```
121
+
111
122
### Dump Feature for Build Mode
112
123
113
124
When using `vite devtools build` to create a static DevTools build, the server cannot execute functions at runtime. The **dump feature** solves this by pre-computing RPC results at build time.
114
125
115
126
#### How It Works
116
127
117
128
1. At build time, `dumpFunctions()` executes your RPC handlers with predefined arguments
118
-
2. Results are stored in `.vdt-rpc-dump.json` in the build output
129
+
2. Results are stored in `.rpc-dump/index.json` in the build output
119
130
3. The static client reads from this JSON file instead of making live RPC calls
120
131
132
+
Dump shard files are written to `.rpc-dump/*.json`. Function names in shard file keys replace `:` with `~` (for example `my-plugin:get-data` -> `my-plugin~get-data`).
133
+
Query record maps are embedded directly in `.rpc-dump/index.json`; no per-function index files are generated.
134
+
121
135
#### Static Functions (Recommended)
122
136
123
137
Functions with `type: 'static'` are **automatically dumped** with no arguments:
> If your data genuinely needs live server state, use `type: 'query'` without dumps. The function will work in dev mode but gracefully fail in build mode.
200
214
215
+
### Organization Convention
216
+
217
+
For plugin-scale RPC modules, we recommend this structure:
218
+
219
+
General guidelines:
220
+
221
+
1. Keep function definitions small and focused: one RPC function per file.
222
+
2. Use `src/node/rpc/index.ts` as the single composition point for registration and type augmentation.
223
+
3. Store plugin-specific runtime options in `src/node/rpc/context.ts` (instead of mutating the base DevTools context object).
224
+
4. Use `context.rpc.invokeLocal(...)` for server-side cross-function composition.
├─ get-info.ts # metadata-style query/static function
234
+
├─ list-files.ts # list operation, reusable by other functions
235
+
├─ read-file.ts # can invoke `list-files` via invokeLocal
236
+
└─ write-file.ts # mutation-oriented function
237
+
```
238
+
239
+
1.`src/node/rpc/index.ts`
240
+
Keep all RPC declarations in one exported list (for example `rpcFunctions`) and centralize type augmentation (`DevToolsRpcServerFunctions`) in the same file.
Use a shared context helper (for example `WeakMap`-backed `set/get`) to provide plugin-specific options across RPC functions without mutating the base context shape.
inputs: files.map(file=> [file.path] as [string]),
308
+
}
309
+
},
310
+
setup: () => ({
311
+
handler: async (path:string) => {
312
+
// ...
313
+
},
314
+
}),
315
+
})
316
+
```
317
+
201
318
## Schema Validation (Optional)
202
319
203
320
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.
Open Vite DevTools and switch to <strong>File Explorer</strong>.
17
+
The panel lists files under <code class="rounded bg-slate-200/70 px-1 py-0.5 font-mono text-xs dark:bg-slate-700/70">playground/src</code> and loads file contents on demand.
18
+
<strong>Save</strong> is available in websocket mode and hidden in static build mode.
0 commit comments