Skip to content

feat(devtools): only enable for selected build environments#22290

Closed
webfansplz wants to merge 1 commit into
vitejs:mainfrom
webfansplz:feat/devtools-environments
Closed

feat(devtools): only enable for selected build environments#22290
webfansplz wants to merge 1 commit into
vitejs:mainfrom
webfansplz:feat/devtools-environments

Conversation

@webfansplz
Copy link
Copy Markdown
Member

Be related to vitejs/devtools#292

Copilot AI review requested due to automatic review settings April 21, 2026 17:34
@webfansplz webfansplz marked this pull request as draft April 21, 2026 17:34
const debug = createDebugger('vite:config', { depth: 10 })
const promisifiedRealpath = promisify(fs.realpath)
const SYMBOL_RESOLVED_CONFIG: unique symbol = Symbol('vite:resolved-config')
type DevToolsConfigWithEnvironments = { environments?: string[] }
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Waiting for vitejs/devtools#296

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds support for enabling Vite DevTools only for selected build environments (linked to vitejs/devtools#292), integrating that selection into both config resolution and builder DevTools startup.

Changes:

  • Introduces getDevToolsEnvironments() to derive the target environment names from devtools.config.environments (defaulting to all environments).
  • Enables build.rolldownOptions.devtools only for the selected environment(s) during resolveConfig().
  • Starts DevTools in the builder only if at least one selected environment was actually built.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
packages/vite/src/node/config.ts Adds environment selection helper and applies devtools enablement per environment during config resolution.
packages/vite/src/node/build.ts Uses the selection helper to decide whether to start DevTools based on which environments were built.

Comment on lines +767 to +769
return (
(devtoolsConfig.config as DevToolsConfigWithEnvironments).environments ??
Object.keys(environments)
Copy link

Copilot AI Apr 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getDevToolsEnvironments returns devtoolsConfig.config.environments verbatim. Because these names can come directly from user config, it should be validated/filtered against the provided environments map using Object.hasOwn(...) (and ideally deduped) before callers index into resolved.environments[name]. Without this, values like __proto__/toString (or simply unknown environment names) can accidentally hit the prototype chain or return undefined, leading to incorrect behavior or potential runtime errors downstream.

Suggested change
return (
(devtoolsConfig.config as DevToolsConfigWithEnvironments).environments ??
Object.keys(environments)
const configuredEnvironments = (
devtoolsConfig.config as DevToolsConfigWithEnvironments
).environments
if (!configuredEnvironments) {
return Object.keys(environments)
}
return [...new Set(configuredEnvironments)].filter((environment) =>
Object.hasOwn(environments, environment),

Copilot uses AI. Check for mistakes.
Comment on lines +2080 to +2085
// Enable `rolldownOptions.devtools` if devtools is enabled and the environment is selected, or for all environments by default.
if (resolved.devtools.enabled) {
resolved.build.rolldownOptions.devtools ??= {}
for (const environmentName of getDevToolsEnvironments(
resolved.devtools,
resolved.environments,
)) {
Copy link

Copilot AI Apr 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change introduces new behavior (enabling rolldownOptions.devtools only for selected environments, and defaulting to all environments when not specified), but there doesn't appear to be a unit test covering it. Consider adding a focused test in packages/vite/src/node/__tests__/config.spec.ts (which already exercises per-environment build option resolution) to assert that only the configured environment(s) get build.rolldownOptions.devtools set, and that the default applies to all environments when devtools.config.environments is omitted.

Copilot generated this review using guidance from repository custom instructions.
@webfansplz webfansplz closed this May 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants