从React Native应用中删除console.log [英] Removing console.log from React Native app
问题描述
在将React Native应用程序部署到商店之前,是否应该删除 console.log()
调用?如果将 console.log()
调用保留在代码中,是否存在某些性能或其他问题?
Should you remove the console.log()
calls before deploying a React Native app to the stores? Are there some performance or other issues that exist if the console.log()
calls are kept in the code?
是否可以通过某些任务运行程序删除日志(类似于与Web相关的任务运行程序,例如Grunt或Gulp)?在开发/调试/测试阶段,我们仍然希望它们,但在生产中则不需要.
Is there a way to remove the logs with some task runner (in a similar fashion to web-related task runners like Grunt or Gulp)? We still want them during our development/debugging/testing phase but not on production.
谢谢!
推荐答案
相信最佳实践是将调试代码包装在诸如...这样的语句中.
believe best practice is to wrap your debug code in statements such as...
if(__DEV__){
console.log();
}
这样,它仅在打包程序或仿真器中运行时运行.更多信息在这里... https://facebook.github.io/react-native/docs/performance#using-consolelog-statements
This way, it only runs when you're running within the packager or emulator. More info here... https://facebook.github.io/react-native/docs/performance#using-consolelog-statements
这篇关于从React Native应用中删除console.log的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!