diff --git a/packages/angular_devkit/build_angular/src/angular-cli-files/models/webpack-configs/common.ts b/packages/angular_devkit/build_angular/src/angular-cli-files/models/webpack-configs/common.ts index 70d970236842..4df73e82b840 100644 --- a/packages/angular_devkit/build_angular/src/angular-cli-files/models/webpack-configs/common.ts +++ b/packages/angular_devkit/build_angular/src/angular-cli-files/models/webpack-configs/common.ts @@ -254,6 +254,22 @@ export function getCommonConfig(wco: WebpackConfigOptions): Configuration { } if (scriptsOptimization) { + let angularGlobalDefinitions = { + ngDevMode: false, + ngI18nClosureMode: false, + }; + + try { + // Try to load known global definitions from @angular/compiler-cli. + // tslint:disable-next-line:no-implicit-dependencies + const GLOBAL_DEFS_FOR_TERSER = require('@angular/compiler-cli').GLOBAL_DEFS_FOR_TERSER; + if (GLOBAL_DEFS_FOR_TERSER) { + angularGlobalDefinitions = GLOBAL_DEFS_FOR_TERSER; + } + } catch { + // Do nothing, the default above will be used instead. + } + const terserOptions = { ecma: wco.supportES2015 ? 6 : 5, warnings: !!buildOptions.verbose, @@ -267,10 +283,7 @@ export function getCommonConfig(wco: WebpackConfigOptions): Configuration { // PURE comments work best with 3 passes. // See https://github.com/webpack/webpack/issues/2899#issuecomment-317425926. passes: 3, - global_defs: { - ngDevMode: false, - ngI18nClosureMode: false, - }, + global_defs: angularGlobalDefinitions, }, // We want to avoid mangling on server. ...(buildOptions.platform == 'server' ? { mangle: false } : {}), @@ -287,7 +300,7 @@ export function getCommonConfig(wco: WebpackConfigOptions): Configuration { } if (wco.tsConfig.options.target !== undefined && - wco.tsConfig.options.target >= ts.ScriptTarget.ES2017) { + wco.tsConfig.options.target >= ts.ScriptTarget.ES2017) { wco.logger.warn(tags.stripIndent` WARNING: Zone.js does not support native async/await in ES2017. These blocks are not intercepted by zone.js and will not triggering change detection.