Solidity and hardhat automatically remove console logs
January 12th, 2023

There is nice plugin that I use as default for my hardhat setup and that is hardhat-preprocessor, so let’s install it

and depending on if you are using TS or plain JS you would add this in .js config

const { removeConsoleLog } = require("hardhat-preprocessor");

and then at start of your config file you define which networks you want to make clean and without console.log statements and import

module.exports = {
    defaultNetwork: "hardhat",
    preprocess: {
        eachLine: removeConsoleLog((hre) => hre.network.name !== "hardhat" && hre.network.name !== "localhost"),
    },

and it will remove it on compile, so you don’t have a tedious task of manually removing it.

Subscribe to N00b21337
Receive the latest updates directly to your inbox.
Mint this entry as an NFT to add it to your collection.
Verification
This entry has been permanently stored onchain and signed by its creator.
More from N00b21337

Skeleton

Skeleton

Skeleton