Skip to content

Commit 4e55bf6

Browse files
committed
fix(@angular-devkit/build-angular): use known Terser global defs
Followup to angular/angular#29929
1 parent 3c4c62b commit 4e55bf6

File tree

1 file changed

+16
-5
lines changed
  • packages/angular_devkit/build_angular/src/angular-cli-files/models/webpack-configs

1 file changed

+16
-5
lines changed

packages/angular_devkit/build_angular/src/angular-cli-files/models/webpack-configs/common.ts

+16-5
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,20 @@ export function getCommonConfig(wco: WebpackConfigOptions): Configuration {
254254
}
255255

256256
if (scriptsOptimization) {
257+
let angularGlobalDefinitions = {
258+
ngDevMode: false,
259+
ngI18nClosureMode: false,
260+
};
261+
262+
try {
263+
// Try to load known global definitions from @angular/compiler-cli.
264+
// tslint:disable-next-line:no-implicit-dependencies
265+
const GLOBAL_DEFS_FOR_TERSER = require('@angular/compiler-cli').GLOBAL_DEFS_FOR_TERSER;
266+
angularGlobalDefinitions = GLOBAL_DEFS_FOR_TERSER;
267+
} catch (_error) {
268+
// Do nothing, the default above will be used instead.
269+
}
270+
257271
const terserOptions = {
258272
ecma: wco.supportES2015 ? 6 : 5,
259273
warnings: !!buildOptions.verbose,
@@ -267,10 +281,7 @@ export function getCommonConfig(wco: WebpackConfigOptions): Configuration {
267281
// PURE comments work best with 3 passes.
268282
// See https://github.com/webpack/webpack/issues/2899#issuecomment-317425926.
269283
passes: 3,
270-
global_defs: {
271-
ngDevMode: false,
272-
ngI18nClosureMode: false,
273-
},
284+
global_defs: angularGlobalDefinitions,
274285
},
275286
// We want to avoid mangling on server.
276287
...(buildOptions.platform == 'server' ? { mangle: false } : {}),
@@ -287,7 +298,7 @@ export function getCommonConfig(wco: WebpackConfigOptions): Configuration {
287298
}
288299

289300
if (wco.tsConfig.options.target !== undefined &&
290-
wco.tsConfig.options.target >= ts.ScriptTarget.ES2017) {
301+
wco.tsConfig.options.target >= ts.ScriptTarget.ES2017) {
291302
wco.logger.warn(tags.stripIndent`
292303
WARNING: Zone.js does not support native async/await in ES2017.
293304
These blocks are not intercepted by zone.js and will not triggering change detection.

0 commit comments

Comments
 (0)