Skip to content

Commit 9627a80

Browse files
authored
fix(webpack): angular 16 build with terser (#10302)
1 parent f64355b commit 9627a80

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

packages/webpack5/__tests__/configuration/__snapshots__/angular.spec.ts.snap

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,10 @@ exports[`angular configuration for android 1`] = `
318318
keep_infinity: true,
319319
drop_console: false,
320320
global_defs: {
321-
__UGLIFIED__: true
321+
__UGLIFIED__: true,
322+
ngDevMode: false,
323+
ngI18nClosureMode: false,
324+
ngJitMode: false
322325
}
323326
},
324327
keep_fnames: true,
@@ -741,7 +744,10 @@ exports[`angular configuration for ios 1`] = `
741744
keep_infinity: true,
742745
drop_console: false,
743746
global_defs: {
744-
__UGLIFIED__: true
747+
__UGLIFIED__: true,
748+
ngDevMode: false,
749+
ngI18nClosureMode: false,
750+
ngJitMode: false
745751
}
746752
},
747753
keep_fnames: true,

packages/webpack5/src/configuration/angular.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,16 @@ import {
1313
getPlatformName,
1414
} from '../helpers/platform';
1515
import base from './base';
16+
// until we can switch to async/await on the webpack config, copy this from '@angular/compiler-cli'
17+
const GLOBAL_DEFS_FOR_TERSER = {
18+
ngDevMode: false,
19+
ngI18nClosureMode: false,
20+
};
21+
22+
const GLOBAL_DEFS_FOR_TERSER_WITH_AOT = {
23+
...GLOBAL_DEFS_FOR_TERSER,
24+
ngJitMode: false,
25+
};
1626

1727
export default function (config: Config, env: IWebpackEnv = _env): Config {
1828
base(config, env);
@@ -269,6 +279,19 @@ export default function (config: Config, env: IWebpackEnv = _env): Config {
269279
])
270280
);
271281

282+
config.optimization.minimizer('TerserPlugin').tap((args) => {
283+
args[0].terserOptions ??= {};
284+
args[0].terserOptions.compress ??= {};
285+
args[0].terserOptions.compress.global_defs ??= {};
286+
args[0].terserOptions.compress.global_defs = {
287+
...args[0].terserOptions.compress.global_defs,
288+
...(disableAOT
289+
? GLOBAL_DEFS_FOR_TERSER
290+
: GLOBAL_DEFS_FOR_TERSER_WITH_AOT),
291+
};
292+
return args;
293+
});
294+
272295
// todo: re-visit later, disabling by default now
273296
// config.plugin('DefinePlugin').tap((args) => {
274297
// args[0] = merge(args[0], {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy