@@ -2,7 +2,7 @@ import path from "path"
22import { fileURLToPath } from "url"
33import fs from "fs"
44import { yellow , red } from "kolorist"
5- import { normalizePath } from "vite"
5+ import { IndexHtmlTransformResult , normalizePath } from "vite"
66import type { PluginOption } from "vite"
77import { compileSFCTemplate } from "./compiler"
88import { parseVueRequest } from "./utils"
@@ -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,7 +111,7 @@ 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
109116 if ( normalizedOptions . appendTo && filename . endsWith ( normalizedOptions . appendTo ) )
110117 return { code : `${ code } \nimport 'virtual:vue-inspector-path:load.js'` }
@@ -124,7 +131,7 @@ function VitePluginInspector(options: VitePluginInspectorOptions = DEFAULT_INSPE
124131 transformIndexHtml ( html ) {
125132 if ( normalizedOptions . appendTo )
126133 return
127- return {
134+ const result : IndexHtmlTransformResult = {
128135 html,
129136 tags : [
130137 {
@@ -137,6 +144,17 @@ function VitePluginInspector(options: VitePluginInspectorOptions = DEFAULT_INSPE
137144 } ,
138145 ] ,
139146 }
147+ if ( normalizedOptions . withComponent ) {
148+ result . tags . push ( {
149+ tag : "script" ,
150+ injectTo : "body" ,
151+ attrs : {
152+ type : "module" ,
153+ src : "/@id/virtual:vue-inspector-path:console.js" ,
154+ } ,
155+ } )
156+ }
157+ return result
140158 } ,
141159 }
142160}
0 commit comments