feat(core): support vite devtools in serve mode - #541
Open
webfansplz wants to merge 2 commits into
Open
Conversation
antfu
approved these changes
Aug 20, 2026
@vitejs/devtools
@vitejs/devtools-kit
@vitejs/devtools-oxc
@vitejs/devtools-rolldown
@vitejs/devtools-vite
@vitejs/devtools-vitest
commit: |
Contributor
There was a problem hiding this comment.
Pull request overview
Prepares @vitejs/devtools for first-class Vite dev-server (serve) integration while preserving existing build-time (Rolldown) behavior. This introduces an apply switch to scope DevTools to serve, build, or both, and ensures the configured environment allowlist also affects dev-time Vite inspection/invalidation behavior.
Changes:
- Add
DevToolsApply('serve' | 'build' | 'all'), default-enable config objects, and gate behavior viaisDevToolsEnabled(). - Update
DevToolsIntegration()to return an async plugin array, usingDevTools()forserveand a build integration plugin forbuild. - Apply the environment allowlist to Vite inspection context creation, HMR notifications, and invalidation tracking; update tests, docs, and public API snapshots accordingly.
Reviewed changes
Copilot reviewed 12 out of 14 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| test/snapshots/tsnapi/@vitejs/devtools/integration.snapshot.d.ts | Snapshot update for DevToolsIntegration() now returning Promise<...[]>. |
| test/snapshots/tsnapi/@vitejs/devtools/config.snapshot.js | Snapshot update to include new isDevToolsEnabled() export. |
| test/snapshots/tsnapi/@vitejs/devtools/config.snapshot.d.ts | Snapshot update for enabled?:, new apply, and DevToolsApply type. |
| packages/vite/src/node/inspect/server.ts | Skip invalidation tracking for disabled environments. |
| packages/vite/src/node/inspect/plugin.ts | Avoid creating env contexts / sending HMR notifications for disabled environments. |
| packages/vite/src/node/inspect/context.ts | Track enabled environment allowlist and prevent exposing disabled env contexts via ViteInspectContext. |
| packages/vite/src/node/tests/inspect-context.test.ts | Add coverage ensuring only configured environments are exposed/recorded. |
| packages/core/src/node/plugins/integration.ts | Gate integration/runDevTools by apply; serve uses DevTools() plugins, build uses Rolldown integration plugin. |
| packages/core/src/node/config.ts | Add apply + default enabling semantics; introduce isDevToolsEnabled(). |
| packages/core/src/node/tests/integration.test.ts | Add coverage for serve/build plugin selection and apply behavior. |
| packages/core/src/node/tests/config.test.ts | Add coverage for normalization defaults and isDevToolsEnabled() logic. |
| packages/core/src/integration.ts | Public API wrapper updated to match async array return. |
| docs/kit/client-context.md | Update injection/troubleshooting wording to reflect config-based integration path. |
| docs/guide/index.md | Update guide to prefer devtools: true, document apply, and clarify embedded customization/build-with-app flow. |
Suppressed comments (1)
packages/core/src/node/plugins/integration.ts:35
runDevTools()starts DevTools once per selected environment, but the environment loop variable is unused andstart()doesn’t take an environment. On multi-environment builds (e.g. client + ssr), this will attempt to start the standalone DevTools server multiple times (likely failing due to port binding / duplicated output). Consider starting DevTools only once when at least one selected environment is present.
for (const _environment of getDevToolsEnvironments(config)) {
try {
const { start } = await import('../cli-commands')
await start(config.devtools.config)
}
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Background
Vite's built-in
devtoolsoption currently supports build-time analysis only. Dev-time integration still requires users to register theDevTools()plugin manually.This PR prepares Vite DevTools for first-class integration with the Vite dev server while preserving the existing build-time behavior.
Changes
devtools.applywith'serve','build', and'all'options.enabled: falseis set.DevToolsIntegration()to return an async plugin array:servereuses the existingDevTools()plugins.buildkeeps the existing Rolldown build integration.Breaking changes
DevToolsIntegration()now returnsPromise<{ name: string }[]>instead of a single{ name: string }plugin.enabled: falseto disable it explicitly.Follow-up
After this PR is merged, I will release these changes as
@vitejs/devtoolsv0.6.I will then open a follow-up PR in Vite core to:
@vitejs/devtoolsv0.6+vite devDevTools()manually