11import aliasPlugin , { type ResolverFunction } from '@rollup/plugin-alias'
2+ import colors from 'picocolors'
23import type { ObjectHook } from 'rolldown'
34import {
45 viteAliasPlugin as nativeAliasPlugin ,
@@ -51,6 +52,10 @@ export async function resolvePlugins(
5152 const buildPlugins = isBundled
5253 ? await ( await import ( '../build' ) ) . resolveBuildPlugins ( config )
5354 : { pre : [ ] , post : [ ] }
55+ const devtoolsIntegrationPlugin =
56+ config . devtools . enabled && ! isWorker
57+ ? await loadDevToolsIntegrationPlugin ( config )
58+ : null
5459 const { modulePreload } = config . build
5560
5661 return [
@@ -121,6 +126,7 @@ export async function resolvePlugins(
121126 ...postPlugins ,
122127
123128 ...buildPlugins . post ,
129+ devtoolsIntegrationPlugin ,
124130
125131 // internal server-only plugins are always applied after everything else
126132 ...( isBundled
@@ -133,6 +139,23 @@ export async function resolvePlugins(
133139 ] . filter ( Boolean ) as Plugin [ ]
134140}
135141
142+ async function loadDevToolsIntegrationPlugin (
143+ config : ResolvedConfig ,
144+ ) : Promise < Plugin | null > {
145+ try {
146+ const { DevToolsIntegration } = await import ( '@vitejs/devtools/integration' )
147+ return DevToolsIntegration ( { config } )
148+ } catch ( error : any ) {
149+ config . logger . error (
150+ colors . red (
151+ `Failed to load Vite DevTools integration: ${ error ?. message || error ?. stack } ` ,
152+ ) ,
153+ { error } ,
154+ )
155+ return null
156+ }
157+ }
158+
136159export function createPluginHookUtils (
137160 plugins : readonly Plugin [ ] ,
138161) : PluginHookUtils {
0 commit comments