Search code examples
reactjsbabeljscreate-react-app

how to remove console.log during production in reactjs created with `create-react-app`


i have create app using npx create-react-app i want to remove console.log() during production but i googled i found this babel-plugin-transform-remove-console plugin configured using this link https://babeljs.io/docs/en/babel-plugin-transform-remove-console/#via-babelrc-recommended unfortunatly it does't seem workout for me. Note i create .babelrc file manually in my root dir.


Solution

    • step 1: npm install babel-plugin-transform-remove-console --save-dev
    • step 2: npm run eject
    • step 3 : Edit package.json file
      "babel": {
        "presets": [
          "react-app"
        ],
        "env": {
          "production": {
            "plugins": [
              "transform-remove-console"
            ]
          }
        }
      }
      
    • step 4 : npm run build