DEV Community

Ajmal Hasan
Ajmal Hasan

Posted on

Removing console.log from React Native app in release (production) using yarn and npm for performance improvement.

1) Babel transpiler can remove console statements for you with the following plugin:

yarn add babel-plugin-transform-remove-console --dev
or
npm i babel-plugin-transform-remove-console --save-dev

2)Edit babel.config.js

module.exports = {
  presets: ['module:metro-react-native-babel-preset'],
  env: {
    production: {
      plugins: ["transform-remove-console"],     //removing consoles.log from app during release (production) versions
    },
  },
};
Enter fullscreen mode Exit fullscreen mode

OR .babelrc

{
  "env": {
    "production": {
      "plugins": ["transform-remove-console"]
    }
  }
}
Enter fullscreen mode Exit fullscreen mode

Discussion (0)