// @ts-nocheck
|
|
/**
|
* 增加debugger组件
|
* @param option
|
* @returns
|
*/
|
export default function VitePluginDevelopmentFilter(option: {
|
tag: string
|
prodTag: string
|
}): any {
|
return {
|
name: 'vite-plugin-development-filter',
|
transform(code, id) {
|
const { tag, prodTag } = option
|
const regexWithCapture = new RegExp(
|
`<${tag}>([\\s\\S]*?)<\\/${tag}>`,
|
'g'
|
)
|
const regexWithCaptureProd = new RegExp(
|
`<${prodTag}>([\\s\\S]*?)<\\/${prodTag}>`,
|
'g'
|
)
|
if (regexWithCapture.test(code)) {
|
if (process.env.NODE_ENV === 'production') {
|
const newCode = code.replaceAll(regexWithCapture, '')
|
return newCode
|
.replaceAll(`<${prodTag}>`, '')
|
.replaceAll(`</${prodTag}>`, '')
|
}
|
}
|
if (regexWithCaptureProd.test(code)) {
|
if (process.env.NODE_ENV === 'development') {
|
const newCode = code.replaceAll(regexWithCaptureProd, '')
|
return newCode
|
}
|
}
|
return code
|
},
|
}
|
}
|