How to Remove console.log from Production in React Native

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 due to security issues.

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 production.

Similar Posts

Leave a Reply