Skip to content

Commit 688b441

Browse files
committed
fix(nuxt): compactible with nuxt 3.3
1 parent 2a6bf89 commit 688b441

File tree

8 files changed

+29
-52
lines changed

8 files changed

+29
-52
lines changed

README.md

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ export default defineConfig({
7171
```ts
7272
// for Nuxt3
7373
// nuxt.config.ts
74-
7574
import { defineNuxtConfig } from 'nuxt/config'
7675
import Inspector from 'vite-plugin-vue-inspector'
7776

@@ -83,18 +82,6 @@ export default defineNuxtConfig({
8382
}],
8483
],
8584
})
86-
87-
// OR
88-
89-
export default defineNuxtConfig({
90-
vite: {
91-
plugins: [
92-
Inspector({
93-
appendTo: 'entry.mjs'
94-
})
95-
]
96-
}
97-
})
9885
```
9986

10087
### Options
@@ -144,7 +131,7 @@ interface VitePluginInspectorOptions {
144131
*
145132
* WARNING: only set this if you know exactly what it does.
146133
*/
147-
appendTo?: string
134+
appendTo?: string | RegExp
148135
}
149136
```
150137

packages/core/README.md

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -83,23 +83,10 @@ export default defineNuxtConfig({
8383
}],
8484
],
8585
})
86-
87-
// OR
88-
89-
export default defineNuxtConfig({
90-
vite: {
91-
plugins: [
92-
Inspector({
93-
appendTo: 'entry.mjs'
94-
})
95-
]
96-
}
97-
})
9886
```
9987

10088
### Options
10189

102-
10390
```ts
10491
interface VitePluginInspectorOptions {
10592
/**
@@ -143,7 +130,7 @@ interface VitePluginInspectorOptions {
143130
*
144131
* WARNING: only set this if you know exactly what it does.
145132
*/
146-
appendTo?: string
133+
appendTo?: string | RegExp
147134
}
148135
```
149136

packages/core/src/index.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ export interface VitePluginInspectorOptions {
6969
*
7070
* WARNING: only set this if you know exactly what it does.
7171
*/
72-
appendTo?: string
72+
appendTo?: string | RegExp
7373
}
7474

7575
const toggleComboKeysMap = {
@@ -98,9 +98,16 @@ export const DEFAULT_INSPECTOR_OPTIONS: VitePluginInspectorOptions = {
9898

9999
function VitePluginInspector(options: VitePluginInspectorOptions = DEFAULT_INSPECTOR_OPTIONS): PluginOption {
100100
const inspectorPath = getInspectorPath()
101-
const normalizedOptions = { ...DEFAULT_INSPECTOR_OPTIONS, ...options }
101+
const normalizedOptions = {
102+
...DEFAULT_INSPECTOR_OPTIONS,
103+
...options,
104+
}
102105
let serverOptions: ServerOptions | undefined
103106

107+
const {
108+
appendTo,
109+
} = normalizedOptions
110+
104111
return {
105112
name: 'vite-plugin-vue-inspector',
106113
enforce: 'pre',
@@ -143,10 +150,12 @@ function VitePluginInspector(options: VitePluginInspectorOptions = DEFAULT_INSPE
143150
if (isJsx || isTpl)
144151
return compileSFCTemplate({ code, id: filename, type: isJsx ? 'jsx' : 'template' })
145152

146-
if (normalizedOptions.appendTo && filename.endsWith(normalizedOptions.appendTo))
147-
return { code: `${code}\nimport 'virtual:vue-inspector-path:load.js'` }
153+
if (!appendTo)
154+
return
148155

149-
return code
156+
if ((typeof appendTo === 'string' && filename.endsWith(appendTo))
157+
|| (appendTo instanceof RegExp && appendTo.test(filename)))
158+
return { code: `${code}\nimport 'virtual:vue-inspector-path:load.js'` }
150159
},
151160
configureServer(server) {
152161
const _printUrls = server.printUrls
@@ -159,7 +168,7 @@ function VitePluginInspector(options: VitePluginInspectorOptions = DEFAULT_INSPE
159168
})
160169
},
161170
transformIndexHtml(html) {
162-
if (normalizedOptions.appendTo)
171+
if (appendTo)
163172
return
164173
return {
165174
html,

packages/core/tsup.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export default defineConfig({
88
if (options.format === 'cjs')
99
options.outExtension = { '.js': '.cjs' }
1010
},
11+
shims: true,
1112
entry: [
1213
'src/index.ts',
1314
],

packages/playground/vue3/vite.config.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,12 @@ import VueJsx from '@vitejs/plugin-vue-jsx'
44
import Inspector from 'vite-plugin-vue-inspector'
55

66
export default defineConfig({
7-
plugins: [Vue(), VueJsx(), Inspector({
8-
enabled: true,
9-
toggleButtonVisibility: 'always',
10-
})],
7+
plugins: [
8+
Vue(),
9+
VueJsx(),
10+
Inspector({
11+
enabled: true,
12+
toggleButtonVisibility: 'always',
13+
}),
14+
],
1115
})

packages/unplugin/README.md

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -83,18 +83,6 @@ export default defineNuxtConfig({
8383
}],
8484
],
8585
})
86-
87-
// OR
88-
89-
export default defineNuxtConfig({
90-
vite: {
91-
plugins: [
92-
Inspector({
93-
appendTo: 'entry.mjs'
94-
})
95-
]
96-
}
97-
})
9886
```
9987

10088
### Options
@@ -143,7 +131,7 @@ interface VitePluginInspectorOptions {
143131
*
144132
* WARNING: only set this if you know exactly what it does.
145133
*/
146-
appendTo?: string
134+
appendTo?: string | RegExp
147135
}
148136
```
149137

packages/unplugin/src/nuxt.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export default (options: Options, nuxt: any) => {
77
nuxt.hook('vite:extendConfig', async (config: any) => {
88
config.plugins = config.plugins || []
99
config.plugins.push(unplugin.vite({
10-
appendTo: 'entry.mjs',
10+
appendTo: /\/entry\.m?js$/,
1111
...options,
1212
}))
1313
})

packages/unplugin/tsup.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ export default <Options>{
77
clean: true,
88
format: ['cjs', 'esm'],
99
dts: true,
10+
shims: true,
1011
onSuccess: 'npm run build:fix',
1112
}

0 commit comments

Comments
 (0)