Skip to content

Commit

Permalink
fix: console append
Browse files Browse the repository at this point in the history
  • Loading branch information
tazyong committed Jul 2, 2022
1 parent f7f97f2 commit bed0b13
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/console.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const warn = console.warn
console.warn = function (...data) {
const skipMsgPrefix = "[Vue warn]: Extraneous non-props attributes ";
const skipMsgPrefix = "[Vue warn]: Extraneous non-props attributes "
let msg = data[0] || ""
if (msg.startsWith(skipMsgPrefix)) {
msg = msg.replace(/\([^)]+\)/, function (match) {
Expand Down
34 changes: 18 additions & 16 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,13 @@ function VitePluginInspector(options: VitePluginInspectorOptions = DEFAULT_INSPE
if (isJsx || isTpl)
return compileSFCTemplate({ code, id: filename, type: isJsx ? "jsx" : "template", withComponent: normalizedOptions.withComponent })

if (normalizedOptions.appendTo && filename.endsWith(normalizedOptions.appendTo))
return { code: `${code}\nimport 'virtual:vue-inspector-path:load.js'` }
if (normalizedOptions.appendTo && filename.endsWith(normalizedOptions.appendTo)) {
const libs = ["import 'virtual:vue-inspector-path:load.js'"]
if (normalizedOptions.withComponent) {
libs.push("import 'virtual:vue-inspector-path:console.js'")
}
return `${code}\n${libs.join('\n')}`
}

return code
},
Expand All @@ -131,21 +136,18 @@ function VitePluginInspector(options: VitePluginInspectorOptions = DEFAULT_INSPE
transformIndexHtml(html) {
if (normalizedOptions.appendTo)
return
const result: IndexHtmlTransformResult = {
html,
tags: [
{
tag: "script",
injectTo: "body",
attrs: {
type: "module",
src: "/@id/virtual:vue-inspector-path:load.js",
},
const tags = [
{
tag: "script",
injectTo: "body" as const,
attrs: {
type: "module",
src: "/@id/virtual:vue-inspector-path:load.js",
},
],
}
},
]
if (normalizedOptions.withComponent) {
result.tags.push({
tags.push({
tag: "script",
injectTo: "body",
attrs: {
Expand All @@ -154,7 +156,7 @@ function VitePluginInspector(options: VitePluginInspectorOptions = DEFAULT_INSPE
},
})
}
return result
return { html, tags }
},
}
}
Expand Down

0 comments on commit bed0b13

Please sign in to comment.