Skip to content

Commit fe485c4

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

File tree

1 file changed

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

1 file changed

+18
-5
lines changed

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

+18-5
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,22 @@ 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+
if (GLOBAL_DEFS_FOR_TERSER) {
267+
angularGlobalDefinitions = GLOBAL_DEFS_FOR_TERSER;
268+
}
269+
} catch {
270+
// Do nothing, the default above will be used instead.
271+
}
272+
257273
const terserOptions = {
258274
ecma: wco.supportES2015 ? 6 : 5,
259275
warnings: !!buildOptions.verbose,
@@ -267,10 +283,7 @@ export function getCommonConfig(wco: WebpackConfigOptions): Configuration {
267283
// PURE comments work best with 3 passes.
268284
// See https://github.com/webpack/webpack/issues/2899#issuecomment-317425926.
269285
passes: 3,
270-
global_defs: {
271-
ngDevMode: false,
272-
ngI18nClosureMode: false,
273-
},
286+
global_defs: angularGlobalDefinitions,
274287
},
275288
// We want to avoid mangling on server.
276289
...(buildOptions.platform == 'server' ? { mangle: false } : {}),
@@ -287,7 +300,7 @@ export function getCommonConfig(wco: WebpackConfigOptions): Configuration {
287300
}
288301

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

0 commit comments

Comments
 (0)