DEV Community

Discussion on: Hide 🙈 all console logs in production with just 3 lines of code

Collapse
 
sagar profile image
Sagar

There is plugin available to remove a console.log statements from project source called babel-plugin-transform-remove-console

Usage:
add plugin name in .babelrc file.

{
  "plugins": ["transform-remove-console"]
}
Enter fullscreen mode Exit fullscreen mode
Collapse
 
sharmakushal profile image
Kushal sharma

Thanks for your suggestions, I will try this one also

Collapse
 
sagar profile image
Sagar

sure 👍🏻

Collapse
 
apvarun profile image
Varun A P ⚡

This is a better option than assigning an empty function to console.log. The empty function removes the option to log anything in your production environment, even for debugging purposes.

If you are using Terser in your build, they provide an option to remove log statements (drop_console: true) from your minified code

Collapse
 
wiseintrovert_31 profile image
Wise Introvert

How do I achieve this in the modern cra-generated applications, where .babelrc file is not exposed and requires me to eject from the react app?