Skip to content

Commit cfcbc24

Browse files
authored
feat: support vite-plugin-inspect for both Vite 5 and 6 (#757)
1 parent bd8651c commit cfcbc24

File tree

7 files changed

+268
-178
lines changed

7 files changed

+268
-178
lines changed

.github/workflows/autofix.yml

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ jobs:
1313
steps:
1414
- uses: actions/checkout@v4
1515
- run: corepack enable
16+
- uses: pnpm/action-setup@v4
1617
- uses: actions/setup-node@v4
1718
with:
1819
node-version: 18

.github/workflows/ci.yml

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ jobs:
1717
steps:
1818
- uses: actions/checkout@v4
1919
- run: corepack enable
20+
- uses: pnpm/action-setup@v4
2021
- uses: actions/setup-node@v4
2122
with:
2223
node-version: 18

packages/devtools/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
"tinyglobby": "catalog:",
7676
"unimport": "catalog:",
7777
"vite-plugin-inspect": "catalog:",
78+
"vite-plugin-inspect-legacy": "npm:[email protected]",
7879
"vite-plugin-vue-inspector": "catalog:",
7980
"which": "catalog:",
8081
"ws": "catalog:"

packages/devtools/src/integrations/analyze-build.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ import type { Nuxt } from 'nuxt/schema'
22
import type { AnalyzeBuildMeta, ModuleOptions } from '../types'
33
import { addVitePlugin } from '@nuxt/kit'
44
import { join } from 'pathe'
5-
import Inspect from 'vite-plugin-inspect'
65
import { getFolderSize } from '../utils/fs'
6+
import { createVitePluginInspect } from './vite-inspect'
77

88
export async function setup(nuxt: Nuxt, options: ModuleOptions) {
99
if (options.viteInspect !== false) {
1010
addVitePlugin(
11-
Inspect({
11+
await createVitePluginInspect({
1212
build: true,
1313
outputDir: join(nuxt.options.analyzeDir, '.vite-inspect'),
1414
}),

packages/devtools/src/integrations/vite-inspect.ts

+16-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,23 @@
1-
import type { ViteInspectAPI } from 'vite-plugin-inspect'
1+
import type { Plugin } from 'vite'
2+
import type { ViteInspectAPI, ViteInspectOptions } from 'vite-plugin-inspect'
23
import type { NuxtDevtoolsServerContext } from '../types'
34
import { addCustomTab } from '@nuxt/devtools-kit'
45
import { addVitePlugin } from '@nuxt/kit'
5-
import Inspect from 'vite-plugin-inspect'
66

7-
export function setup({ nuxt, rpc }: NuxtDevtoolsServerContext) {
8-
const plugin = Inspect()
7+
export async function createVitePluginInspect(options?: ViteInspectOptions): Promise<Plugin> {
8+
const { version } = await import('vite')
9+
const major = Number.parseInt(version.split('.')[0], 10)
10+
11+
if (major < 6) {
12+
return await import('vite-plugin-inspect-legacy').then(r => r.default(options))
13+
}
14+
else {
15+
return await import('vite-plugin-inspect').then(r => r.default(options))
16+
}
17+
}
18+
19+
export async function setup({ nuxt, rpc }: NuxtDevtoolsServerContext) {
20+
const plugin = await createVitePluginInspect()
921
addVitePlugin(plugin)
1022

1123
let api: ViteInspectAPI | undefined

pnpm-lock.yaml

+241-166
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pnpm-workspace.yaml

+6-6
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ catalog:
2020
'@nuxt/test-utils': ^3.14.4
2121
'@opentelemetry/api': ^1.9.0
2222
'@parcel/watcher': ^2.5.0
23-
'@pinia/nuxt': ^0.7.0
23+
'@pinia/nuxt': ^0.8.0
2424
'@types/diff': ^6.0.0
2525
'@types/markdown-it': ^14.1.2
2626
'@types/markdown-it-link-attributes': ^3.0.5
@@ -84,12 +84,12 @@ catalog:
8484
nitropack: ^2.10.4
8585
nuxt: ^3.14.1592
8686
nuxt-eslint-auto-explicit-import: ^0.1.1
87-
nypm: ^0.4.0
87+
nypm: ^0.4.1
8888
ofetch: ^1.4.1
8989
ohash: ^1.1.4
9090
pathe: ^1.1.2
9191
perfect-debounce: ^1.0.0
92-
pinia: ^2.2.7
92+
pinia: ^2.2.8
9393
pkg-types: ^1.2.1
9494
prompts: ^2.4.2
9595
quicktype-core: ^23.0.170
@@ -107,16 +107,16 @@ catalog:
107107
typescript: 5.6.3
108108
ua-parser-js: ^1.0.39
109109
unbuild: ^2.0.0
110-
unimport: ^3.13.4
110+
unimport: ^3.14.1
111111
unocss: ^0.64.1
112112
unplugin-vue-markdown: ^0.26.3
113113
v-lazy-show: ^0.2.4
114114
vanilla-jsoneditor: ^0.23.8
115115
vis-data: ^7.1.9
116116
vis-network: ^9.1.9
117-
vite: ^5.4.11
117+
vite: ^6.0.1
118118
vite-hot-client: ^0.2.4
119-
vite-plugin-inspect: ^0.8.8
119+
vite-plugin-inspect: ^0.10.3
120120
vite-plugin-vue-inspector: 5.1.3
121121
vitest: ^2.1.6
122122
vue: ^3.5.13

0 commit comments

Comments
 (0)