We always tend to forget to remove console.log
statements before pushing our code to production. While these logs are useful for debugging, they can clutter the console, expose unnecessary details, and even affect performance. Instead of manually removing them every time, why not be smart and automate the process? Next.js provides a simple built-in way to strip out console.log
statements in production.
next.config.js
file in your project’s root directory.module.exports = {
compiler: {
removeConsole: process.env.NODE_ENV === "production",
},
};
removeConsole
option ensures that all console.log
statements are removed when building for production.By using the removeConsole
option in next.config.js
, you can easily prevent console.log
statements from appearing in production builds, keeping your application clean and efficient.