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.