Skip to content

Commit 86abd8e

Browse files
authored
feat(devtools): restore Vue DevTools through vite-plugin-vue-devtools v9 (#1099)
1 parent 04f3cd0 commit 86abd8e

8 files changed

Lines changed: 525 additions & 152 deletions

File tree

‎packages/devtools-kit/src/_types/options.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@ export interface ModuleOptions {
3737
*/
3838
componentInspector?: boolean
3939

40+
/**
41+
* Enable the Vue DevTools integration, which registers Vue DevTools'
42+
* own dock entry next to the Nuxt one.
43+
*
44+
* @default true
45+
*/
46+
vueDevTools?: boolean
47+
4048
/**
4149
* Enable the Vite Inspect integration.
4250
*

‎packages/devtools/package.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
"tinyglobby": "catalog:prod",
7676
"unstorage": "catalog:prod",
7777
"verkit": "catalog:prod",
78+
"vite-plugin-vue-devtools": "catalog:prod",
7879
"vite-plugin-vue-tracer": "catalog:prod"
7980
},
8081
"devDependencies": {

‎packages/devtools/src/constant.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const isSandboxed = provider === 'stackblitz' || provider === 'codesandbox'
66
export const defaultOptions: ModuleOptions = {
77
enabled: undefined, // determine multiple conditions
88
componentInspector: true,
9+
vueDevTools: true,
910
viteInspect: true,
1011
dataInspector: true,
1112
codeServer: {
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import type { PluginWithDevTools } from '@vitejs/devtools-kit'
2+
import type { NuxtDevtoolsServerContext } from '../types'
3+
import { addPluginTemplate, addVitePlugin } from '@nuxt/kit'
4+
import { vueDevtools } from 'vite-plugin-vue-devtools'
5+
import { skipInSSR } from '../server-rpc/skip-in-ssr'
6+
7+
export function setup({ nuxt }: NuxtDevtoolsServerContext) {
8+
if (!nuxt.options.dev || nuxt.options.test)
9+
return
10+
11+
// Added isomorphically — `{ server: false }` would strip the `devtools`
12+
// property (see the note in `module-main.ts`) — so guard the dock
13+
// registration against Nuxt's SSR Vite instance, which would otherwise
14+
// register a duplicate `vue-devtools` dock. Same pattern as the module's
15+
// own dock registration.
16+
// `vueDevtools()` always produces plain plugin objects; its declared
17+
// `PluginOption[]` return type is wider than that.
18+
const plugins = (vueDevtools() as PluginWithDevTools[]).map((plugin) => {
19+
const { devtools } = plugin
20+
if (!devtools?.setup)
21+
return plugin
22+
return {
23+
...plugin,
24+
devtools: {
25+
...devtools,
26+
setup: (ctx: Parameters<typeof devtools.setup>[0]) =>
27+
skipInSSR(ctx) ? undefined : devtools.setup(ctx),
28+
},
29+
}
30+
})
31+
addVitePlugin(plugins)
32+
33+
// Nuxt has no Vite HTML entry for the plugin's own injection to hook into;
34+
// load the Vue DevTools client hook through an early Nuxt client plugin
35+
// instead.
36+
addPluginTemplate({
37+
filename: 'devtools/vue-devtools-client.mjs',
38+
name: 'vue-devtools-client',
39+
mode: 'client',
40+
order: -1_000,
41+
getContents: () => [
42+
`import 'virtual:vue-devtools-client'`,
43+
``,
44+
`export default () => {}`,
45+
``,
46+
].join('\n'),
47+
})
48+
}

‎packages/devtools/src/module-main.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ export async function enableModule(options: ModuleOptions, nuxt: Nuxt) {
116116
// pre-bundle here.
117117
'nuxt > @nuxt/devtools > @vitejs/devtools-kit/client',
118118
'nuxt > @nuxt/devtools > error-stack-parser-es',
119+
'nuxt > @nuxt/devtools > vite-plugin-vue-devtools/client',
119120
'nuxt > @nuxt/devtools > vite-plugin-vue-tracer/client/overlay',
120121
)
121122
}
@@ -371,6 +372,9 @@ window.__NUXT_DEVTOOLS_TIME_METRIC__.appInit = Date.now()
371372
if (options.componentInspector !== false)
372373
await import('./integrations/vue-tracer').then(({ setup }) => setup(ctx))
373374

375+
if (options.vueDevTools !== false)
376+
await import('./integrations/vue-devtools').then(({ setup }) => setup(ctx))
377+
374378
if (options.codeServer?.enabled === false && options.vscode !== undefined) {
375379
deprecate(nuxt, 'NDT_DEP_0008', {
376380
api: 'devtools.vscode',

‎packages/devtools/test/devtools-origin.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ describe('vite DevTools origin', () => {
7171
dataInspector: false,
7272
viteInspect: false,
7373
componentInspector: false,
74+
vueDevTools: false,
7475
codeServer: { enabled: false },
7576
} as any, nuxt)
7677

‎pnpm-lock.yaml‎

Lines changed: 460 additions & 152 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎pnpm-workspace.yaml‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ minimumReleaseAgeExclude:
1313
- '@vitejs/devtools'
1414
- devframe
1515
- vite-plugin-inspect@12.0.2
16+
- vite-plugin-vue-devtools@9.0.0-beta.0
1617
- '@devframes/hub-ui'
1718
- '@devframes/json-render-ui'
1819
- '@devframes/service-open'
@@ -247,6 +248,7 @@ catalogs:
247248
unstorage: ^1.17.5
248249
verkit: ^0.4.0
249250
vite-plugin-inspect: ^12.0.2
251+
vite-plugin-vue-devtools: ^9.0.0-beta.0
250252
vite-plugin-vue-tracer: ^1.5.0
251253
types:
252254
'@nuxt/schema': *nuxt-schema

0 commit comments

Comments
 (0)