Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/vite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
"@types/escape-html": "^1.0.4",
"@types/pnpapi": "^0.0.5",
"@vitest/utils": "4.1.5",
"@vitejs/devtools": "^0.1.15",
"@vitejs/devtools": "^0.1.18",
"artichokie": "^0.4.3",
"baseline-browser-mapping": "^2.10.23",
"cac": "^7.0.0",
Expand Down Expand Up @@ -140,7 +140,7 @@
},
"peerDependencies": {
"@types/node": "^20.19.0 || >=22.12.0",
"@vitejs/devtools": "^0.1.0",
"@vitejs/devtools": "^0.1.18",
"esbuild": "^0.27.0 || ^0.28.0",
"jiti": ">=1.21.0",
"less": "^4.0.0",
Expand Down
11 changes: 6 additions & 5 deletions packages/vite/src/node/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1847,14 +1847,15 @@ export async function createBuilder(
return output
},
async runDevTools() {
const devtoolsConfig = config.devtools
if (devtoolsConfig.enabled) {
if (config.devtools.enabled) {
try {
const { start } = await import(`@vitejs/devtools/cli-commands`)
await start(devtoolsConfig.config)
const { runDevTools } = await import('@vitejs/devtools/integration')
await runDevTools(builder)
} catch (e) {
Comment thread
webfansplz marked this conversation as resolved.
config.logger.error(
colors.red(`Failed to run Vite DevTools: ${e.message || e.stack}`),
colors.red(
`Failed to run Vite DevTools: ${e?.message || e?.stack}`,
),
{ error: e },
)
}
Expand Down
5 changes: 0 additions & 5 deletions packages/vite/src/node/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2072,11 +2072,6 @@ export async function resolveConfig(
resolved.build.ssrEmitAssets || resolved.build.emitAssets
}

// Enable `rolldownOptions.devtools` if devtools is enabled
if (resolved.devtools.enabled) {
resolved.build.rolldownOptions.devtools ??= {}
}

applyDepOptimizationOptionCompat(resolved)
await setOptimizeDepsPluginNames(resolved)

Expand Down
23 changes: 23 additions & 0 deletions packages/vite/src/node/plugins/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import aliasPlugin, { type ResolverFunction } from '@rollup/plugin-alias'
import colors from 'picocolors'
import type { ObjectHook } from 'rolldown'
import {
viteAliasPlugin as nativeAliasPlugin,
Expand Down Expand Up @@ -51,6 +52,10 @@ export async function resolvePlugins(
const buildPlugins = isBundled
? await (await import('../build')).resolveBuildPlugins(config)
: { pre: [], post: [] }
const devtoolsIntegrationPlugin =
config.devtools.enabled && !isWorker
? await loadDevToolsIntegrationPlugin(config)
: null
const { modulePreload } = config.build

return [
Expand Down Expand Up @@ -121,6 +126,7 @@ export async function resolvePlugins(
...postPlugins,

...buildPlugins.post,
devtoolsIntegrationPlugin,

// internal server-only plugins are always applied after everything else
...(isBundled
Expand All @@ -133,6 +139,23 @@ export async function resolvePlugins(
].filter(Boolean) as Plugin[]
}

async function loadDevToolsIntegrationPlugin(
config: ResolvedConfig,
): Promise<Plugin | null> {
try {
const { DevToolsIntegration } = await import('@vitejs/devtools/integration')
return DevToolsIntegration({ config })
} catch (error: any) {
config.logger.error(
colors.red(
`Failed to load Vite DevTools integration: ${error?.message || error?.stack}`,
),
{ error },
)
return null
}
}

export function createPluginHookUtils(
plugins: readonly Plugin[],
): PluginHookUtils {
Expand Down
2 changes: 1 addition & 1 deletion playground/devtools/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
},
"devDependencies": {
"vite": "workspace:*",
"@vitejs/devtools": "^0.1.15"
"@vitejs/devtools": "^0.1.18"
}
}
Loading