Skip to content

Commit e2a3ee9

Browse files
committed
feat: respect vite base path option
1 parent a50a258 commit e2a3ee9

File tree

1 file changed

+35
-33
lines changed

1 file changed

+35
-33
lines changed

packages/core/src/index.ts

Lines changed: 35 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { fileURLToPath } from 'node:url'
33
import fs from 'node:fs'
44
import { bold, dim, green, yellow } from 'kolorist'
55
import { normalizePath } from 'vite'
6-
import type { PluginOption, ServerOptions } from 'vite'
6+
import type { PluginOption, ResolvedConfig, ServerOptions } from 'vite'
77
import MagicString from 'magic-string'
88
import { compileSFCTemplate } from './compiler'
99
import { idToFile, parseVueRequest } from './utils'
@@ -29,59 +29,59 @@ export interface VueInspectorClient {
2929

3030
export interface VitePluginInspectorOptions {
3131
/**
32-
* Vue version
33-
* @default 3
34-
*/
32+
* Vue version
33+
* @default 3
34+
*/
3535
vue?: 2 | 3
3636

3737
/**
38-
* Default enable state
39-
* @default false
40-
*/
38+
* Default enable state
39+
* @default false
40+
*/
4141
enabled?: boolean
4242

4343
/**
44-
* Define a combo key to toggle inspector
45-
* @default 'control-shift' on windows, 'meta-shift' on other os
46-
*
47-
* any number of modifiers `control` `shift` `alt` `meta` followed by zero or one regular key, separated by -
48-
* examples: control-shift, control-o, control-alt-s meta-x control-meta
49-
* Some keys have native behavior (e.g. alt-s opens history menu on firefox).
50-
* To avoid conflicts or accidentally typing into inputs, modifier only combinations are recommended.
51-
* You can also disable it by setting `false`.
52-
*/
44+
* Define a combo key to toggle inspector
45+
* @default 'control-shift' on windows, 'meta-shift' on other os
46+
*
47+
* any number of modifiers `control` `shift` `alt` `meta` followed by zero or one regular key, separated by -
48+
* examples: control-shift, control-o, control-alt-s meta-x control-meta
49+
* Some keys have native behavior (e.g. alt-s opens history menu on firefox).
50+
* To avoid conflicts or accidentally typing into inputs, modifier only combinations are recommended.
51+
* You can also disable it by setting `false`.
52+
*/
5353
toggleComboKey?: string | false
5454

5555
/**
56-
* Toggle button visibility
57-
* @default 'active'
58-
*/
56+
* Toggle button visibility
57+
* @default 'active'
58+
*/
5959
toggleButtonVisibility?: 'always' | 'active' | 'never'
6060

6161
/**
62-
* Toggle button display position
63-
* @default top-right
64-
*/
62+
* Toggle button display position
63+
* @default top-right
64+
*/
6565
toggleButtonPos?: 'top-right' | 'top-left' | 'bottom-right' | 'bottom-left'
6666

6767
/**
68-
* append an import to the module id ending with `appendTo` instead of adding a script into body
69-
* useful for frameworks that do not support transformIndexHtml hook (e.g. Nuxt3)
70-
*
71-
* WARNING: only set this if you know exactly what it does.
72-
*/
68+
* append an import to the module id ending with `appendTo` instead of adding a script into body
69+
* useful for frameworks that do not support transformIndexHtml hook (e.g. Nuxt3)
70+
*
71+
* WARNING: only set this if you know exactly what it does.
72+
*/
7373
appendTo?: string | RegExp
7474

7575
/**
76-
* Customize openInEditor host (e.g. http://localhost:3000)
77-
* @default false
78-
*/
76+
* Customize openInEditor host (e.g. http://localhost:3000)
77+
* @default false
78+
*/
7979
openInEditorHost?: string | false
8080

8181
/**
8282
* lazy load inspector times (ms)
8383
* @default false
84-
*/
84+
*/
8585
lazyLoad?: number | false
8686

8787
/**
@@ -133,6 +133,7 @@ function VitePluginInspector(options: VitePluginInspectorOptions = DEFAULT_INSPE
133133
...options,
134134
}
135135
let serverOptions: ServerOptions | undefined
136+
let config: ResolvedConfig
136137

137138
const {
138139
vue,
@@ -187,7 +188,7 @@ function VitePluginInspector(options: VitePluginInspectorOptions = DEFAULT_INSPE
187188
return
188189

189190
if ((typeof appendTo === 'string' && filename.endsWith(appendTo))
190-
|| (appendTo instanceof RegExp && appendTo.test(filename)))
191+
|| (appendTo instanceof RegExp && appendTo.test(filename)))
191192
return { code: `${code}\nimport 'virtual:vue-inspector-path:load.js'` }
192193
},
193194
configureServer(server) {
@@ -211,13 +212,14 @@ function VitePluginInspector(options: VitePluginInspectorOptions = DEFAULT_INSPE
211212
injectTo: 'head',
212213
attrs: {
213214
type: 'module',
214-
src: '/@id/virtual:vue-inspector-path:load.js',
215+
src: `${config.base || '/'}@id/virtual:vue-inspector-path:load.js`,
215216
},
216217
},
217218
],
218219
}
219220
},
220221
configResolved(resolvedConfig) {
222+
config = resolvedConfig
221223
serverOptions = resolvedConfig.server
222224
},
223225
},

0 commit comments

Comments
 (0)