Skip to content

Commit 2c4e6f6

Browse files
authored
docs: mention @vitejs/devtools/client/inject for explicit devtools client injection (#266)
1 parent 8d0a7fe commit 2c4e6f6

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

docs/guide/index.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,18 @@ pnpm dev
110110

111111
Then open your app in the browser and open the DevTools panel.
112112

113+
#### Projects without an HTML entry
114+
115+
The embedded DevTools client is usually injected through Vite's `transformIndexHtml` hook. If your app does not start from an HTML entry, keep the `DevTools()` plugin enabled and import the client injector manually in your client entry instead:
116+
117+
```ts twoslash
118+
import '@vitejs/devtools/client/inject'
119+
```
120+
121+
This loads the same DevTools client that would normally be added to `index.html`. Put it in a browser entry such as `main.ts` or `entry.client.ts`, not in server-only files or shared SSR entry files.
122+
123+
If your project does have an HTML entry, avoid importing `@vitejs/devtools/client/inject` in addition to the HTML injection, as that would inject the client twice and create duplicate dock elements.
124+
113125
#### Building with the App
114126

115127
You can also generate a static DevTools build alongside your app's build output by enabling the `build.withApp` option:

packages/core/src/node/plugins/injection.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export function DevToolsInjection(): Plugin {
77
return {
88
name: 'vite:devtools:injection',
99
enforce: 'post',
10+
apply: 'serve',
1011
transformIndexHtml() {
1112
const fileUrl = process.env.VITE_DEVTOOLS_LOCAL_DEV
1213
? normalize(join(dirDist, '..', 'src/client/inject/index.ts'))

0 commit comments

Comments
 (0)