解决方案
方案一,通过ast解析console 将变量名放在console后面,奈何esbuild不支持ast操作(不是我不会 哈哈哈哈), 故放弃。
方案二,既然vue能代理对象,那么console是不是也能被代理。
实践
第一步代理console,将原始的console,用全局变量originConsole保存起来,以便后续使用 withLogging 函数拦截console.log 重写log参数
js复制代码const originConsole = window.console;
var console = new Proxy(window.console, {
get(target, property) {
if(property === 'log') {
return withLogging(target[property])
}
return target[property] },
})
大约 1 分钟