Skip to content

Commit 1ca88c7

Browse files
committed
chore: update
2 parents 26b05d7 + 2c19392 commit 1ca88c7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+3731
-2290
lines changed

docs/.vitepress/config.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,20 @@ export default defineConfig({
1616
// https://vitepress.dev/reference/default-theme-config
1717
nav: [
1818
{ text: 'Guide', link: '/guide/' },
19+
{ text: 'Kit', link: '/kit/' },
1920
],
2021

2122
sidebar: [
2223
{
2324
text: 'Introduction',
2425
items: [
2526
{ text: 'Getting Started', link: '/guide/' },
26-
{ text: 'Why Vite DevTools', link: '/guide/why' },
27+
],
28+
},
29+
{
30+
text: 'DevTools Kit',
31+
items: [
32+
{ text: 'Introduction', link: '/kit/' },
2733
],
2834
},
2935
],

docs/guide/index.md

Lines changed: 37 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,31 @@
11
# Getting Started
22

3-
## Overview
4-
5-
Vite DevTools is...
6-
7-
## Try Vite DevTools Online
8-
9-
You can try Vite DevTools online on [StackBlitz](https://vite.new).
10-
11-
## Installation
12-
13-
::: code-group
14-
15-
```bash [npm]
16-
npm install -D @vitejs/devtools
3+
> [!WARNING]
4+
> Vite DevTools is still in development and not yet ready for production use.
5+
> And currently Vite DevTools is designed only for Vite-Rolldown's build mode.
6+
> Dev mode and normal Vite are not supported yet.
7+
8+
If you want to give an early preview, you can try it out by building this project from source, or install the preview build with the following steps:
9+
10+
Switch your Vite to [Rolldown Vite](https://vite.dev/guide/rolldown#how-to-try-rolldown):
11+
12+
<!-- eslint-skip -->
13+
```json [package.json]
14+
{
15+
"dependencies": {
16+
"vite": "^7.0.0" // [!code --]
17+
"vite": "npm:rolldown-vite@latest" // [!code ++]
18+
}
19+
}
1720
```
1821

19-
```bash [yarn]
20-
yarn add -D @vitejs/devtools
21-
```
22+
Install the DevTools plugin:
2223

23-
```bash [pnpm]
24+
```bash
2425
pnpm add -D @vitejs/devtools
2526
```
2627

27-
```bash [bun]
28-
bun add -D @vitejs/devtools
29-
```
30-
31-
:::
32-
33-
## Configuration
28+
Enable the DevTools plugin in your Vite config and turn on the debug mode for Rolldown:
3429

3530
```ts [vite.config.ts] twoslash
3631
import { DevTools } from '@vitejs/devtools'
@@ -40,5 +35,22 @@ export default defineConfig({
4035
plugins: [
4136
DevTools(),
4237
],
38+
build: {
39+
rolldownOptions: {
40+
debug: {}, // enable debug mode
41+
},
42+
}
4343
})
4444
```
45+
46+
Run your Vite build, to generate the Rolldown build metadata:
47+
48+
```bash
49+
pnpm build
50+
```
51+
52+
Open the DevTools panel in your browser to play with the DevTools:
53+
54+
```bash
55+
pnpm dev
56+
```

docs/guide/why.md

Lines changed: 0 additions & 1 deletion
This file was deleted.

docs/kit/index.md

Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
---
2+
outline: deep
3+
---
4+
5+
# DevTools Kit
6+
7+
> [!WARNING]
8+
> The API is still in development and may change in any version. If you are building on top of it, please mind the version of packages you are using and warn your users about the experimental status.
9+
10+
Vite DevTools offers a shared infrastructure for building custom DevTools for Vite and the frameworks on top of Vite.
11+
12+
// TODO: some introduction from Anthony's Talk
13+
14+
## DevTools Plugin
15+
16+
Plugin/framework authors can extend the DevTools by enhancing the DevTools infrastructure with custom data visualization, actions, and more. A DevTools plugin is a **superset** of Vite plugin.
17+
18+
To get started, in your Vite plugin project, first you need to install the `@vitejs/devtools-kit` package. Usually it's fine to be a dev dependency as we only need it for types on Node.js side.
19+
20+
```zsh
21+
pnpm install -D @vitejs/devtools-kit
22+
```
23+
24+
Then referencing it in your plugin code, it will augment the `Plugin` interface with the `devtools` property.
25+
26+
Inside `devtools.setup`, you will get tools to register custom data visualization, actions, and more.
27+
28+
```ts {1,9-14}
29+
/// <reference types="@vitejs/devtools-kit" />
30+
import { Plugin } from 'vite'
31+
32+
export default function myPlugin(): Plugin {
33+
return {
34+
name: 'my-plugin',
35+
// Do other plugin stuff...
36+
transform(code, id) {},
37+
// Devtools setup
38+
devtools: {
39+
setup(ctx) {
40+
console.log('My plugin setup')
41+
},
42+
},
43+
}
44+
}
45+
```
46+
47+
### Register A Dock Entry
48+
49+
Dock entries are the most straight-forward entry for users to interact with your DevTools integration. Usually it will be presented as a floating panel inside user's app, or a sidebar in browser extension mode or standalone mode. "Dock" refers to macOS's Dock, where you switch between different items by clicking on them.
50+
51+
To register a dock entry, you can use the `ctx.docks.register` method to add a new dock entry. The easiest approach is to register a iframe-based dock entry. Here we use VueUse's docs as an example:
52+
53+
```ts {6-12}
54+
export default function VueUseDevToolsDocs(): Plugin {
55+
return {
56+
name: 'vueuse:devtools:docs',
57+
devtools: {
58+
setup(ctx) {
59+
ctx.docks.register({
60+
id: 'vueuse:docs',
61+
title: 'VueUse',
62+
icon: 'https://vueuse.org/favicon.svg',
63+
type: 'iframe',
64+
url: 'https://vueuse.org',
65+
})
66+
},
67+
}
68+
}
69+
}
70+
```
71+
72+
The more practical usage is to build an local webpage to draw your own views and do other interactions.
73+
74+
For example, if we hosted a local custom view at `/.my-app`, we can register it as a dock entry like this:
75+
76+
```ts {6}
77+
ctx.docks.register({
78+
id: 'my-app',
79+
title: 'My App',
80+
icon: 'https://my-app.com/logo.svg',
81+
type: 'iframe',
82+
url: '/.my-app',
83+
})
84+
```
85+
86+
DevTools can also handles the page hosting for you, assume you have your built SPA page under `./dist/client`, you can register it as a dock entry like this:
87+
88+
```ts {2}
89+
const pathClientDist = fileURLToPath(new URL('../dist/client', import.meta.url))
90+
ctx.views.hostStatic('/.my-app', pathClientDist)
91+
ctx.docks.register({
92+
id: 'my-app',
93+
title: 'My App',
94+
icon: 'https://my-app.com/logo.svg',
95+
type: 'iframe',
96+
url: '/.my-app',
97+
})
98+
```
99+
100+
This way DevTools will handle the dev server middleware to host the static files for you, and also copy the static files to the dist directory when in production build.
101+
102+
### Register An Action
103+
104+
Instead of an iframe panel, sometime you might want to register an action button to trigger some actions to the client app. For example, you want to enable a temporary inspector tool to inspect the DOM of the client app and want to have the button on the DevTools dock.
105+
106+
```ts {6}
107+
ctx.docks.register({
108+
id: 'dom-inspector',
109+
title: 'DOM Inspector',
110+
type: 'action',
111+
action: {
112+
importFrom: 'vite-plugin-my-inspector/vite-devtools-action',
113+
importName: 'default',
114+
},
115+
icon: 'ph:cursor-duotone',
116+
})
117+
```
118+
119+
And in your package, you can export the sub entrypoint for the action.
120+
121+
```ts [src/vite-devtools-action.ts]
122+
import type { DevToolsClientScriptContext } from '@vitejs/devtools-kit/client'
123+
124+
export default function setupDevToolsAction(ctx: DevToolsClientScriptContext) {
125+
// Setup action will only execute when the entry is activated the first time
126+
127+
// Register listeners to handle the events from the client app
128+
ctx.current.events.on('entry:activated', () => {
129+
alert('DOM inspector started! ')
130+
})
131+
}
132+
```
133+
134+
And in your package.json, you can export the sub entrypoint:
135+
136+
```json [package.json]
137+
{
138+
"name": "vite-plugin-my-inspector",
139+
"exports": {
140+
"./vite-devtools-action": "./dist/vite-devtools-action.mjs"
141+
}
142+
}
143+
```
144+
145+
That's it! When users install your plugin, they can use your action button in the dock, and when the entry is activated the first time, the action will be executed in the user's app for you to handle the logic.
146+
147+
## References
148+
149+
The docs might not cover all the details, please help us to improve it by submitting PRs. And in the meantime, you can refer to the following existing DevTools integrations for reference (but note they might not always be up to date with the latest API changes):
150+
151+
- [UnoCSS Inspector](https://github.com/unocss/unocss/blob/25c0dd737132dc20b257c276ee2bc3ccc05e2974/packages-integrations/inspector/src/index.ts#L140-L150) (a simple iframe-based dock entry)
152+
- `vite-plugin-vue-tracer` (a simple action button to trigger the DOM inspector)
153+
- [plugin hook](https://github.com/antfu/vite-plugin-vue-tracer/blob/9f86fe723543405eea5d30588fe783796193bfd8/src/plugin.ts#L139-L157)
154+
- [client script](https://github.com/antfu/vite-plugin-vue-tracer/blob/main/src/client/vite-devtools.ts)

netlify.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[build]
22
publish = "docs/.vitepress/dist"
3-
command = "pnpm run docs:build"
3+
command = "pnpm run build && pnpm run docs:build"
44

55
[build.environment]
66
NODE_VERSION = "24"

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"type": "module",
3-
"version": "0.0.0-alpha.11",
3+
"version": "0.0.0-alpha.17",
44
"private": true,
55
"packageManager": "[email protected]",
66
"scripts": {

packages/core/package.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@vitejs/devtools",
33
"type": "module",
4-
"version": "0.0.0-alpha.11",
4+
"version": "0.0.0-alpha.17",
55
"description": "Vite DevTools",
66
"author": "VoidZero Inc.",
77
"license": "MIT",
@@ -45,22 +45,27 @@
4545
"dev:standalone": "cd src/client/standalone && vite dev",
4646
"prepack": "pnpm build",
4747
"play": "DEBUG='vite:devtools:*' pnpm -C playground run dev",
48+
"play:standlone": "DEBUG='vite:devtools:*' pnpm -C playground run dev:standalone",
4849
"cli": "DEBUG='vite:devtools:*' tsx src/node/cli.ts",
4950
"play:build": "pnpm -C playground run build"
5051
},
5152
"peerDependencies": {
52-
"vite": "catalog:build"
53+
"vite": "*"
5354
},
5455
"dependencies": {
5556
"@vitejs/devtools-kit": "workspace:*",
5657
"@vitejs/devtools-rpc": "workspace:*",
5758
"@vitejs/devtools-vite": "workspace:*",
59+
"birpc": "catalog:deps",
60+
"birpc-x": "catalog:deps",
5861
"cac": "catalog:deps",
5962
"debug": "catalog:deps",
6063
"launch-editor": "catalog:deps",
6164
"mlly": "catalog:deps",
65+
"nanoevents": "catalog:deps",
6266
"open": "catalog:deps",
6367
"pathe": "catalog:deps",
68+
"perfect-debounce": "catalog:deps",
6469
"sirv": "catalog:deps",
6570
"ws": "catalog:deps"
6671
},
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
{
22
"name": "playground",
33
"type": "module",
4-
"version": "0.0.0-alpha.11",
4+
"version": "0.0.0-alpha.17",
55
"private": true,
66
"scripts": {
77
"dev": "VITE_DEVTOOLS_LOCAL_DEV=true vite",
8+
"dev:standlone": "DEBUG='vite:devtools:*' VITE_DEVTOOLS_LOCAL_DEV=true tsx ../src/node/cli.ts",
89
"build": "vite build && vite-devtools"
910
}
1011
}

0 commit comments

Comments
 (0)