Skip to content

Commit

Permalink
refactor: 使用 eruda 进行日志监控 - 生产阶段去掉调试
Browse files Browse the repository at this point in the history
  • Loading branch information
terwer committed May 23, 2023
1 parent 01449b1 commit bede15b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
10 changes: 8 additions & 2 deletions src/utils/simple-logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@
* questions.
*/

import { isDev } from "./constants.ts"

/**
* 使用 eruda 更好的控制日志
*/
const console = (window as any).eruda.get("console")
const console = isDev ? (window as any).eruda.get("console") : window.console

/**
* 简单的日志接口
Expand Down Expand Up @@ -69,7 +71,11 @@ export const createLogger = (name: string): ILogger => {
}

return {
debug: (msg: string, obj?: any) => log("DEBUG", msg, obj),
debug: (msg: string, obj?: any) => {
if (isDev) {
log("DEBUG", msg, obj)
}
},
info: (msg: string, obj?: any) => log("INFO", msg, obj),
warn: (msg: string, obj?: any) => {
const time = formatDate(new Date())
Expand Down
22 changes: 12 additions & 10 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,20 @@ export default defineConfig({
minify: !isWatch,
inject: {
// 在 body 标签底部插入指定的 JavaScript 文件
tags: [
{
tag: "script",
attrs: {
src: "./libs/eruda/eruda.js",
},
injectTo: "head-prepend",
},
],
tags: isWatch
? [
{
tag: "script",
attrs: {
src: "./libs/eruda/eruda.js",
},
injectTo: "head-prepend",
},
]
: [],
data: {
title: "eruda",
injectScript: `<script>eruda.init();</script>`,
injectScript: isWatch ? `<script>eruda.init();</script>` : "",
},
},
}),
Expand Down

0 comments on commit bede15b

Please sign in to comment.