Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
8 changes: 8 additions & 0 deletions packages/devtools-kit/src/_types/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ export interface ModuleOptions {
*/
componentInspector?: boolean

/**
* Enable the Vue DevTools integration, which registers Vue DevTools'
* own dock entry next to the Nuxt one.
*
* @default true
*/
vueDevTools?: boolean

/**
* Enable the Vite Inspect integration.
*
Expand Down
1 change: 1 addition & 0 deletions packages/devtools/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
"tinyglobby": "catalog:prod",
"unstorage": "catalog:prod",
"verkit": "catalog:prod",
"vite-plugin-vue-devtools": "catalog:prod",
"vite-plugin-vue-tracer": "catalog:prod"
},
"devDependencies": {
Expand Down
1 change: 1 addition & 0 deletions packages/devtools/src/constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const isSandboxed = provider === 'stackblitz' || provider === 'codesandbox'
export const defaultOptions: ModuleOptions = {
enabled: undefined, // determine multiple conditions
componentInspector: true,
vueDevTools: true,
viteInspect: true,
dataInspector: true,
codeServer: {
Expand Down
48 changes: 48 additions & 0 deletions packages/devtools/src/integrations/vue-devtools.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import type { PluginWithDevTools } from '@vitejs/devtools-kit'
import type { NuxtDevtoolsServerContext } from '../types'
import { addPluginTemplate, addVitePlugin } from '@nuxt/kit'
import { vueDevtools } from 'vite-plugin-vue-devtools'
import { skipInSSR } from '../server-rpc/skip-in-ssr'

export function setup({ nuxt }: NuxtDevtoolsServerContext) {
if (!nuxt.options.dev || nuxt.options.test)
return

// Added isomorphically — `{ server: false }` would strip the `devtools`
// property (see the note in `module-main.ts`) — so guard the dock
// registration against Nuxt's SSR Vite instance, which would otherwise
// register a duplicate `vue-devtools` dock. Same pattern as the module's
// own dock registration.
// `vueDevtools()` always produces plain plugin objects; its declared
// `PluginOption[]` return type is wider than that.
const plugins = (vueDevtools() as PluginWithDevTools[]).map((plugin) => {
const { devtools } = plugin
if (!devtools?.setup)
return plugin
return {
...plugin,
devtools: {
...devtools,
setup: (ctx: Parameters<typeof devtools.setup>[0]) =>
skipInSSR(ctx) ? undefined : devtools.setup(ctx),
},
}
})
addVitePlugin(plugins)

// Nuxt has no Vite HTML entry for the plugin's own injection to hook into;
// load the Vue DevTools client hook through an early Nuxt client plugin
// instead.
addPluginTemplate({
filename: 'devtools/vue-devtools-client.mjs',
name: 'vue-devtools-client',
mode: 'client',
order: -1_000,
getContents: () => [
`import 'virtual:vue-devtools-client'`,
``,
`export default () => {}`,
``,
].join('\n'),
})
}
4 changes: 4 additions & 0 deletions packages/devtools/src/module-main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ export async function enableModule(options: ModuleOptions, nuxt: Nuxt) {
// pre-bundle here.
'nuxt > @nuxt/devtools > @vitejs/devtools-kit/client',
'nuxt > @nuxt/devtools > error-stack-parser-es',
'nuxt > @nuxt/devtools > vite-plugin-vue-devtools/client',
'nuxt > @nuxt/devtools > vite-plugin-vue-tracer/client/overlay',
)
}
Expand Down Expand Up @@ -371,6 +372,9 @@ window.__NUXT_DEVTOOLS_TIME_METRIC__.appInit = Date.now()
if (options.componentInspector !== false)
await import('./integrations/vue-tracer').then(({ setup }) => setup(ctx))

if (options.vueDevTools !== false)
await import('./integrations/vue-devtools').then(({ setup }) => setup(ctx))

if (options.codeServer?.enabled === false && options.vscode !== undefined) {
deprecate(nuxt, 'NDT_DEP_0008', {
api: 'devtools.vscode',
Expand Down
1 change: 1 addition & 0 deletions packages/devtools/test/devtools-origin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ describe('vite DevTools origin', () => {
dataInspector: false,
viteInspect: false,
componentInspector: false,
vueDevTools: false,
codeServer: { enabled: false },
} as any, nuxt)

Expand Down
612 changes: 460 additions & 152 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions pnpm-workspace.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ minimumReleaseAgeExclude:
- '@vitejs/devtools'
- devframe
- vite-plugin-inspect@12.0.2
- vite-plugin-vue-devtools@9.0.0-beta.0
- '@devframes/hub-ui'
- '@devframes/json-render-ui'
- '@devframes/service-open'
Expand Down Expand Up @@ -247,6 +248,7 @@ catalogs:
unstorage: ^1.17.5
verkit: ^0.4.0
vite-plugin-inspect: ^12.0.2
vite-plugin-vue-devtools: ^9.0.0-beta.0
vite-plugin-vue-tracer: ^1.5.0
types:
'@nuxt/schema': *nuxt-schema
Expand Down
Loading