Skip to content

Commit 44e47f0

Browse files
fix(core): start standalone DevTools once for multi-environment builds (#613)
1 parent 4c37162 commit 44e47f0

2 files changed

Lines changed: 27 additions & 14 deletions

File tree

‎packages/core/src/node/__tests__/integration.test.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,16 @@ describe('devToolsIntegration', () => {
169169
)
170170
})
171171

172+
it('starts standalone DevTools once for multiple build environments', async () => {
173+
const plugins = await DevToolsIntegration(createIntegrationOptions('build'))
174+
const config = createResolvedConfig('build', { client: {} as never, ssr: {} as never })
175+
Object.assign(config, { plugins, devtools: normalizeDevToolsConfig({ apply: 'build' }, 'localhost') })
176+
177+
await runDevTools({ config })
178+
179+
expect(startDevTools).toHaveBeenCalledTimes(1)
180+
})
181+
172182
it('does not run standalone DevTools for a manual plugin config', async () => {
173183
const config = createResolvedConfig('build', { client: {} as never })
174184
Object.assign(config, {

‎packages/core/src/node/plugins/integration.ts‎

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -54,20 +54,23 @@ export async function runDevTools(
5454

5555
if (!isDevToolsEnabled(devtoolsConfig, config.command))
5656
return
57-
for (const _environment of getDevToolsEnvironments(config, devtoolsConfig)) {
58-
try {
59-
const { startDevTools } = await import('../start')
60-
await startDevTools({
61-
...devtoolsConfig.config,
62-
root: devtoolsConfig.config.root ?? config.root,
63-
}, devtoolsConfig)
64-
}
65-
catch (error: any) {
66-
config.logger.error(
67-
`Failed to run Vite DevTools: ${error?.message || error?.stack || error}`,
68-
{ error },
69-
)
70-
}
57+
58+
// A single standalone server covers every environment, so start it once.
59+
if (!getDevToolsEnvironments(config, devtoolsConfig).length)
60+
return
61+
62+
try {
63+
const { startDevTools } = await import('../start')
64+
await startDevTools({
65+
...devtoolsConfig.config,
66+
root: devtoolsConfig.config.root ?? config.root,
67+
}, devtoolsConfig)
68+
}
69+
catch (error: any) {
70+
config.logger.error(
71+
`Failed to run Vite DevTools: ${error?.message || error?.stack || error}`,
72+
{ error },
73+
)
7174
}
7275
}
7376

0 commit comments

Comments
 (0)