skip to Main Content

Using console.log statements is one of the most common patterns to debug in JavaScript applications in general, including React Native apps. Leaving the console statements in the source code when publishing React Native apps can cause some big bottlenecks in the JavaScript thread.

2

Answers


  1. Chosen as BEST ANSWER
    npm install babel-plugin-transform-remove-console --save-dev
    yarn add babel-plugin-transform-remove-console -D
    

    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
        },
      },
    };
    

    OR .babelrc

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

  2. just put those line in index.js file:

    if (!__DEV__) {
      console.log = () => {}
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search