@@ -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
7575const toggleComboKeysMap = {
@@ -98,9 +98,16 @@ export const DEFAULT_INSPECTOR_OPTIONS: VitePluginInspectorOptions = {
9898
9999function 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,
0 commit comments