Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

reactJS disable console.log system wide

I have console.log all over the place. Removing them all is not good as I might need them again. Is there way I can do something like this for entire react app?

if(env === 'production'){
  console.log= function(){}
}
like image 974
angry kiwi Avatar asked Jun 08 '16 16:06

angry kiwi


2 Answers

In your index.js file, check if you're running in dev or production mode.
Disable console.log if you're in production mode.

if (process.env.NODE_ENV !== "development")
    console.log = () => {};
like image 62
HBSKan Avatar answered Sep 26 '22 19:09

HBSKan


Given you are using React, it is likely that you are already using babel as a part of your build process.

You can use this babel plugin to remove all the console.* function invocations in the build phase.

like image 20
lorefnon Avatar answered Sep 22 '22 19:09

lorefnon