@@ -20,6 +20,12 @@ export interface VitePluginInspectorOptions {
2020 */
2121 vue ?: 2 | 3
2222
23+ /**
24+ * Inspect with vue component
25+ * @default true
26+ */
27+ withComponent ?: boolean
28+
2329 /**
2430 * Default enable state
2531 * @default false
@@ -60,6 +66,7 @@ export interface VitePluginInspectorOptions {
6066
6167const DEFAULT_INSPECTOR_OPTIONS : VitePluginInspectorOptions = {
6268 vue : 3 ,
69+ withComponent : true ,
6370 enabled : false ,
6471 toggleComboKey : process . platform === "win32" ? "control-shift" : "meta-shift" ,
6572 toggleButtonVisibility : "active" ,
@@ -104,10 +111,15 @@ function VitePluginInspector(options: VitePluginInspectorOptions = DEFAULT_INSPE
104111 const isTpl = filename . endsWith ( ".vue" ) && query . type !== "style"
105112
106113 if ( isJsx || isTpl )
107- return compileSFCTemplate ( { code, id : filename , type : isJsx ? "jsx" : "template" } )
114+ return compileSFCTemplate ( { code, id : filename , type : isJsx ? "jsx" : "template" , withComponent : normalizedOptions . withComponent } )
108115
109- if ( normalizedOptions . appendTo && filename . endsWith ( normalizedOptions . appendTo ) )
110- return { code : `${ code } \nimport 'virtual:vue-inspector-path:load.js'` }
116+ if ( normalizedOptions . appendTo && filename . endsWith ( normalizedOptions . appendTo ) ) {
117+ const libs = [ "import 'virtual:vue-inspector-path:load.js'" ]
118+ if ( normalizedOptions . withComponent ) {
119+ libs . push ( "import 'virtual:vue-inspector-path:console.js'" )
120+ }
121+ return `${ code } \n${ libs . join ( '\n' ) } `
122+ }
111123
112124 return code
113125 } ,
@@ -124,19 +136,27 @@ function VitePluginInspector(options: VitePluginInspectorOptions = DEFAULT_INSPE
124136 transformIndexHtml ( html ) {
125137 if ( normalizedOptions . appendTo )
126138 return
127- return {
128- html,
129- tags : [
130- {
131- tag : "script" ,
132- injectTo : "body" ,
133- attrs : {
134- type : "module" ,
135- src : "/@id/virtual:vue-inspector-path:load.js" ,
136- } ,
139+ const tags = [
140+ {
141+ tag : "script" ,
142+ injectTo : "body" as const ,
143+ attrs : {
144+ type : "module" ,
145+ src : "/@id/virtual:vue-inspector-path:load.js" ,
146+ } ,
147+ } ,
148+ ]
149+ if ( normalizedOptions . withComponent ) {
150+ tags . push ( {
151+ tag : "script" ,
152+ injectTo : "body" ,
153+ attrs : {
154+ type : "module" ,
155+ src : "/@id/virtual:vue-inspector-path:console.js" ,
137156 } ,
138- ] ,
157+ } )
139158 }
159+ return { html, tags }
140160 } ,
141161 }
142162}
0 commit comments