fix(webpack): angular 16 build with terser (#10302)

This commit is contained in:
Eduardo Speroni
2023-06-06 11:54:25 -03:00
committed by GitHub
parent f64355ba7a
commit 9627a80f27
2 changed files with 31 additions and 2 deletions

View File

@ -318,7 +318,10 @@ exports[`angular configuration for android 1`] = `
keep_infinity: true,
drop_console: false,
global_defs: {
__UGLIFIED__: true
__UGLIFIED__: true,
ngDevMode: false,
ngI18nClosureMode: false,
ngJitMode: false
}
},
keep_fnames: true,
@ -741,7 +744,10 @@ exports[`angular configuration for ios 1`] = `
keep_infinity: true,
drop_console: false,
global_defs: {
__UGLIFIED__: true
__UGLIFIED__: true,
ngDevMode: false,
ngI18nClosureMode: false,
ngJitMode: false
}
},
keep_fnames: true,

View File

@ -13,6 +13,16 @@ import {
getPlatformName,
} from '../helpers/platform';
import base from './base';
// until we can switch to async/await on the webpack config, copy this from '@angular/compiler-cli'
const GLOBAL_DEFS_FOR_TERSER = {
ngDevMode: false,
ngI18nClosureMode: false,
};
const GLOBAL_DEFS_FOR_TERSER_WITH_AOT = {
...GLOBAL_DEFS_FOR_TERSER,
ngJitMode: false,
};
export default function (config: Config, env: IWebpackEnv = _env): Config {
base(config, env);
@ -269,6 +279,19 @@ export default function (config: Config, env: IWebpackEnv = _env): Config {
])
);
config.optimization.minimizer('TerserPlugin').tap((args) => {
args[0].terserOptions ??= {};
args[0].terserOptions.compress ??= {};
args[0].terserOptions.compress.global_defs ??= {};
args[0].terserOptions.compress.global_defs = {
...args[0].terserOptions.compress.global_defs,
...(disableAOT
? GLOBAL_DEFS_FOR_TERSER
: GLOBAL_DEFS_FOR_TERSER_WITH_AOT),
};
return args;
});
// todo: re-visit later, disabling by default now
// config.plugin('DefinePlugin').tap((args) => {
// args[0] = merge(args[0], {