Say Goodbye to console.log from Production environment

Say Goodbye to console.log from Production environment

ยท

1 min read

I have been working on a project with Next.js since last month and used the console.log statement in lots of components & files even though I don't remember. Usually, we use it to check API responses and some other areas of the application.

Making console statements public is not a good idea at all, it may bring your app at a security risk. Checking every file, and deleting the statement is very time-consuming & boring too. As a developer, we all hate boring tasks so, in the article here we discuss how you can say goodbye to console.log in your Next.js app from the Production environment in just less than 1 minute .

Sounds good! let's goooo...๐Ÿ˜Ž

๐Ÿ‘‰ Follow the steps mentioned below -

  1. Install the babel-plugin-transform-remove-console package as a development dependency.

  2. Create a .babelrc file at the root of your project, copy the below content & that's all.

{
    "presets": [
        "next/babel"
    ],
    "env": {
        "production": {
            "plugins": [
                "transform-remove-console"
            ]
        }
    }
}

This is just a short trick that I used to enhance my productivity, even you should use it next time.

Reference:

ย