Skip to content

Commit

Permalink
fix(@angular-devkit/build-angular): use known Terser global defs
Browse files Browse the repository at this point in the history
  • Loading branch information
filipesilva authored and alexeagle committed Apr 24, 2019
1 parent c8b4f4a commit eec39a2
Showing 1 changed file with 18 additions and 5 deletions.
Expand Up @@ -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,
Expand All @@ -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 } : {}),
Expand All @@ -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.
Expand Down

0 comments on commit eec39a2

Please sign in to comment.