From e8f85e3d9a5fc57ffd46c0df3c31277d52ff2de8 Mon Sep 17 00:00:00 2001 From: Jimmy Lai Date: Wed, 28 Sep 2022 15:10:59 +0200 Subject: [PATCH] misc: add MANGLING_DEBUG option (#40958) Context: I am doing some work re: bundle size so I'm spending a lot of time looking at the bundles we generate. This debug options basically deactives mangling and beautifies the output whilst keeping the dead code elimination from Terser which is helpful for me to check what I'm removing. this is what the output is like with it. image ## Bug - [ ] Related issues linked using `fixes #number` - [ ] Integration tests added - [ ] Errors have a helpful link attached, see `contributing.md` ## Feature - [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR. - [ ] Related issues linked using `fixes #number` - [ ] Integration tests added - [ ] Documentation added - [ ] Telemetry added. In case of a feature if it's used or not. - [ ] Errors have a helpful link attached, see `contributing.md` ## Documentation / Examples - [ ] Make sure the linting passes by running `pnpm lint` - [ ] The "examples guidelines" are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md) --- packages/next/build/webpack-config.ts | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/packages/next/build/webpack-config.ts b/packages/next/build/webpack-config.ts index 615bb7d6fb..28c04a0265 100644 --- a/packages/next/build/webpack-config.ts +++ b/packages/next/build/webpack-config.ts @@ -897,13 +897,28 @@ export default async function getBaseWebpackConfig( comparisons: false, inline: 2, // https://github.com/vercel/next.js/issues/7178#issuecomment-493048965 }, - mangle: { safari10: true }, + mangle: { + safari10: true, + ...(process.env.__NEXT_MANGLING_DEBUG + ? { + toplevel: true, + module: true, + keep_classnames: true, + keep_fnames: true, + } + : {}), + }, output: { ecma: 5, safari10: true, comments: false, // Fixes usage of Emoji and certain Regex ascii_only: true, + ...(process.env.__NEXT_MANGLING_DEBUG + ? { + beautify: true, + } + : {}), }, }