Skip to content

Commit 8759cf3

Browse files
committed
feat: improve vite devtools integration
1 parent 94fc4ef commit 8759cf3

File tree

5 files changed

+408
-27
lines changed

5 files changed

+408
-27
lines changed

packages/devtools/package.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,14 @@
4646
"prepack": "pnpm build"
4747
},
4848
"peerDependencies": {
49+
"@vitejs/devtools": "*",
4950
"vite": ">=6.0"
5051
},
52+
"peerDependenciesMeta": {
53+
"@vitejs/devtools": {
54+
"optional": true
55+
}
56+
},
5157
"dependencies": {
5258
"@nuxt/devtools-kit": "workspace:*",
5359
"@nuxt/devtools-wizard": "workspace:*",
@@ -102,6 +108,7 @@
102108
"@unocss/preset-icons": "catalog:buildtools",
103109
"@unocss/preset-uno": "catalog:buildtools",
104110
"@unocss/runtime": "catalog:frontend",
111+
"@vitejs/devtools": "catalog:buildtools",
105112
"@vitest/ui": "catalog:cli",
106113
"@vue/devtools-applet": "catalog:frontend",
107114
"@vueuse/nuxt": "catalog:buildtools",

packages/devtools/src/module-main.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,9 @@ export async function enableModule(options: ModuleOptions, nuxt: Nuxt) {
6060
})
6161

6262
if (options.viteDevTools) {
63-
// eslint-disable-next-line no-console
64-
console.log('[nuxt-devtools] Enabling experimental Vite DevTools integration')
63+
logger.info('[nuxt-devtools] Enabling experimental Vite DevTools integration')
64+
const DevTools = await import('@vitejs/devtools').then(r => r.DevTools())
65+
addVitePlugin(DevTools)
6566
addVitePlugin({
6667
name: 'nuxt:devtools',
6768
devtools: {
@@ -76,7 +77,10 @@ export async function enableModule(options: ModuleOptions, nuxt: Nuxt) {
7677
},
7778
},
7879
})
79-
// TODO: disable builtin devtools panel for vite devtools
80+
addPlugin({
81+
src: join(runtimeDir, 'plugins/vite-devtools.client'),
82+
mode: 'client',
83+
})
8084
}
8185

8286
// Mainly for the injected runtime plugin to access the settings
@@ -88,7 +92,12 @@ export async function enableModule(options: ModuleOptions, nuxt: Nuxt) {
8892
{
8993
...defaultTabOptions.ui,
9094
// When not enabled explicitly, we hide the panel by default
91-
showPanel: enabledExplicitly ? true : null,
95+
// When Vite DevTools is enabled, we hide the panel by default
96+
showPanel: options.viteDevTools
97+
? false
98+
: enabledExplicitly
99+
? true
100+
: null,
92101
},
93102
{ root: nuxt.options.rootDir },
94103
)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { defineNuxtPlugin } from '#imports'
2+
3+
export default defineNuxtPlugin(() => {
4+
import('@vitejs/devtools/client/inject')
5+
})

0 commit comments

Comments
 (0)