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:
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
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
Create React App is the easiest and most available way to get into React. And ejecting your app is seen as the gateway to being a “Real React Developer.” I'm not normally for gatekeeping, but ejecting is worth avoiding.
The Yellow warning box in React Native can be both helpful and annoying. There are many errors that can be ignored but end up blocking necessary pieces of the application. To disable the yellow box place console. disableYellowBox = true; anywhere in your application.
If you've previously installed create-react-app globally via npm install -g create-react-app , we recommend you uninstall the package using npm uninstall -g create-react-app or yarn global remove create-react-app to ensure that npx always uses the latest version.
For debugging purposes, I often use console. log statements in React Native and Expo applications. A babel plugin called babel-plugin-transform-remove-console takes care of removing any console statements from the code.
Add this to index.js
if (process.env.NODE_ENV !== 'development') {
console.log = () => {}
}
Note that this will only suppress the messages, it will not strip them from your deployed code.
Don't do this for library modules, it will disable console.log for the parent project.
There is some movement on this issue on the CRA repo... go give it support/thumbs up here https://github.com/facebook/create-react-app/pull/9222
References: How to quickly and conveniently disable all console.log statements in my code?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With