How to Remove console.log from Production in React Native

Last Updated on April 10, 2021.

When you are developing a react native app, it’s usual to use console.log function for debugging purposes. Extensive use of console.log may make your app slow. Hence, it would be good to remove console.log from production.

There are libraries such as redux logger which uses console.log. Manually removing console.log is not easy. Luckily, there’s a simple way to remove console.log from production with little effort.

The babel-plugin-transform-remove-console babel plugin helps you to remove all console.* calls. Install the library using the following command.

npm install babel-plugin-transform-remove-console --save-dev

Create a file named .babelrc in your project folder. Then add the following configuration.

{
  "env": {
    "production": {
      "plugins": ["transform-remove-console"]
    }
  }
}

That’s it. The console.log calls will be removed from the production.

Leave a Reply

%d bloggers like this: