wms_mp_weixin/src/utils/debug-log.ts
2026-10-17 18:05:39 +08:00

23 lines
1.1 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* 开发期日志(生产构建自动失效)
*
* 为什么要这层封装:
* 1. `console.log` 会原样打进线上包,真机开调试模式就能看到 ——
* 里面一旦带**登录码 / token / 用户信息**就是信息泄露(安全风险,不是"代码不干净"那么简单)
* 2. 提审自检要求「移除调试代码 / console.log」,但排查问题又确实需要它
*
* 做法:只在 **开发态** 输出。Vite 在构建时会把 `import.meta.env.DEV` 折叠成常量,
* 生产包里这个分支直接消失(可用 `dist/build/mp-weixin/utils/debug-log.js` 验证)。
*
* ⚠️ 约定(比"用不用 debugLog"更重要):
* - **登录码 / token / 密码 / 完整用户对象** —— 连 `debugLog` 都不许打印,直接删
* - `console.warn` / `console.error` 保留:只用于异常诊断,同样不得带上述敏感数据
*/
/** 开发期日志:仅 `import.meta.env.DEV` 为真时输出 */
export function debugLog(...args: unknown[]): void {
if (import.meta.env.DEV) {
console.log(...args)
}
}