How to remove console.log for Production in NextJS
Jasser Mark Arioste
Sometimes we need to remove console.log for Production in NextJS. I've seen many tutorials that modify the console.log function but I think this tutorial is the cleanest and most elegant way to remove console.log messages.
We'll just have to modify next.config.js
:
/** @type {import('next').NextConfig} */ const nextConfig = { ... compiler: { removeConsole: process.env.NODE_ENV === "production" }, }
12345678
NextJS v12 config has a compiler
option removeConsole
that accepts a boolean
value, so we just have to check if the NODE_ENV
is equal to "production".
That's it!
If you like tutorials like these please leave a like or subscribe to our newsletter down below!
Credits: Image by Julius Silver from Pixabay