Skip to content

Commit 52233c1

Browse files
authored
build: Fix minifier options for webpack builds (#78717)
### What? Adjust the options for the SWC minifier to disable character frequency analysis for webpack builds correctly. ### Why? #77887 only adjusted the option for rspack. ### How? Follow-up of #77887
1 parent 443b243 commit 52233c1

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

packages/next/src/build/webpack-config.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1207,7 +1207,10 @@ export default async function getBaseWebpackConfig(
12071207
// @ts-ignore No typings yet
12081208
const { MinifyPlugin } =
12091209
require('./webpack/plugins/minify-webpack-plugin/src/index.js') as typeof import('./webpack/plugins/minify-webpack-plugin/src')
1210-
new MinifyPlugin({ noMangling }).apply(compiler)
1210+
new MinifyPlugin({
1211+
noMangling,
1212+
disableCharFreq: !isClient,
1213+
}).apply(compiler)
12111214
},
12121215
// Minify CSS
12131216
(compiler: webpack.Compiler) => {

packages/next/src/build/webpack/plugins/minify-webpack-plugin/src/index.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ function buildError(error: any, file: string) {
3232
const debugMinify = process.env.NEXT_DEBUG_MINIFY
3333

3434
export class MinifyPlugin {
35-
constructor(private options: { noMangling?: boolean }) {}
35+
constructor(
36+
private options: { noMangling?: boolean; disableCharFreq?: boolean }
37+
) {}
3638

3739
async optimize(
3840
compiler: any,
@@ -47,7 +49,11 @@ export class MinifyPlugin {
4749
RawSource: typeof sources.RawSource
4850
}
4951
) {
50-
const mangle = !this.options.noMangling
52+
const mangle = this.options.noMangling
53+
? false
54+
: {
55+
disableCharFreq: !!this.options.disableCharFreq,
56+
}
5157
const compilationSpan =
5258
getCompilationSpan(compilation)! || getCompilationSpan(compiler)
5359

0 commit comments

Comments
 (0)