在不弹出的情况下在Create React App中删除日志语句 [英] Removing log statements in Create React App without ejecting
问题描述
在开发Apps时,我使用了许多 console.log()
语句(我的意思是很多)。我如何才能从
创建React应用
中不弹出
删除它们完全实现:
I use lots of console.log()
statements while developing Apps (and I mean LOTS). How exactly can I remove them without "ejecting"
from a
Create React App
What I considered but not sure how exactly to implement:
在我的package.json中:
In my package.json:
"build": "react-scripts build && uglifyjs --compress drop_console build/static/js/main.xxxxx.js -o build/static/js/main.xxxxx.js
但是,我怎么确切知道上的
文件,所以我可以调用此命令并以相同的文件名保存输出js文件 hash
后缀main.js
However How exactly can I know the hash
suffix on the main.js
file so I can call this command and save the output js file with same filename
推荐答案
如果只想禁止日志输出,则可以包装 console.log
并使用它
If you just want to suppress log output you could wrap console.log
and use that instead
const log = (...msgs) => {
if (process.env.NODE_ENV === 'development') console.log(...msgs)
}
您可以导入/导出此文件,但这听起来很痛苦。添加到 global
You can import / export this, but that sounds like a pain. Seems like a good thing to add to global
global.log = log
global.log('will only log in dev')
这篇关于在不弹出的情况下在Create React App中删除日志语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!