#Minify Next.js output

1 messages · Page 1 of 1 (latest)

fossil auroraBOT
#

Hi @feral coyote. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

Yes, it is possible to minify the Next.js build output. By default, Next.js uses its SWC compiler for minification since version 13, which is 7x faster than Terser. However, if you still need Terser for any reason, you can configure it in your next.config.js file by setting swcMinify to false:

module.exports = {
 swcMinify: false,
}

(Source: Next.js Docs (https://nextjs.org/docs/architecture/nextjs-compiler#minification))

If you want to use SWC for minification, you can opt-in by setting swcMinify to true in your next.config.js file:

module.exports = {
 swcMinify: true,
}

(Source: Next.js Docs (https://nextjs.org/docs/pages/building-your-application/upgrading/version-12#swc-replacing-terser-for-minification))

Please note that the SWC minification is an opt-in feature to ensure it can be tested against more real-world Next.js applications before it becomes the default.

As for using other bundlers like tsup, the extracts do not provide information on how to configure them with Next.js. However, Next.js has its own built-in compiler that replaces Babel for individual files and Terser for minifying output bundles, providing a significant speed boost (17x faster than Babel).

(Source: Next.js Docs (https://nextjs.org/docs/architecture/nextjs-compiler))

If you encounter any issues with the minification process, such as inefficiently transpiled code, it's recommended to report them for further investigation and improvement.

(Source: Github Issue (https://github.com/vercel/next.js/issues/37142))

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: