@@ -23,7 +23,7 @@ import {
23
23
} from 'webpack' ;
24
24
import { RawSource } from 'webpack-sources' ;
25
25
import { AssetPatternClass , ExtraEntryPoint } from '../../../browser/schema' ;
26
- import { BuildBrowserFeatures } from '../../../utils/build-browser-features ' ;
26
+ import { BuildBrowserFeatures , fullDifferential } from '../../../utils' ;
27
27
import { BundleBudgetPlugin } from '../../plugins/bundle-budget' ;
28
28
import { CleanCssWebpackPlugin } from '../../plugins/cleancss-webpack-plugin' ;
29
29
import { NamedLazyChunksPlugin } from '../../plugins/named-chunks-plugin' ;
@@ -59,19 +59,23 @@ export function getCommonConfig(wco: WebpackConfigOptions): Configuration {
59
59
const entryPoints : { [ key : string ] : string [ ] } = { } ;
60
60
61
61
const targetInFileName = getEsVersionForFileName (
62
- buildOptions . scriptTargetOverride ,
62
+ fullDifferential ? buildOptions . scriptTargetOverride : tsConfig . options . target ,
63
63
buildOptions . esVersionInFileName ,
64
64
) ;
65
65
66
66
if ( buildOptions . main ) {
67
67
entryPoints [ 'main' ] = [ path . resolve ( root , buildOptions . main ) ] ;
68
68
}
69
69
70
+ let differentialLoadingNeeded = false ;
70
71
if ( wco . buildOptions . platform !== 'server' ) {
71
72
const buildBrowserFeatures = new BuildBrowserFeatures (
72
73
projectRoot ,
73
74
tsConfig . options . target || ScriptTarget . ES5 ,
74
75
) ;
76
+
77
+ differentialLoadingNeeded = buildBrowserFeatures . isDifferentialLoadingNeeded ( ) ;
78
+
75
79
if ( ( buildOptions . scriptTargetOverride || tsConfig . options . target ) === ScriptTarget . ES5 ) {
76
80
if (
77
81
buildOptions . es5BrowserSupport ||
@@ -90,16 +94,28 @@ export function getCommonConfig(wco: WebpackConfigOptions): Configuration {
90
94
: [ noModuleScript ] ;
91
95
}
92
96
93
- // For differential loading we don't need to generate a seperate polyfill file
97
+ // For full build differential loading we don't need to generate a seperate polyfill file
94
98
// because they will be loaded exclusivly based on module and nomodule
95
- const polyfillsChunkName = buildBrowserFeatures . isDifferentialLoadingNeeded ( )
96
- ? 'polyfills'
97
- : 'polyfills-es5' ;
99
+ const polyfillsChunkName =
100
+ fullDifferential && differentialLoadingNeeded ? 'polyfills' : 'polyfills-es5' ;
98
101
99
102
entryPoints [ polyfillsChunkName ] = [ path . join ( __dirname , '..' , 'es5-polyfills.js' ) ] ;
103
+ if ( ! fullDifferential && differentialLoadingNeeded ) {
104
+ // Add zone.js legacy support to the es5 polyfills
105
+ // This is a noop execution-wise if zone-evergreen is not used.
106
+ entryPoints [ polyfillsChunkName ] . push ( 'zone.js/dist/zone-legacy' ) ;
107
+ }
100
108
if ( ! buildOptions . aot ) {
109
+ // If not performing a full differential build the JIT polyfills need to be added to ES5
110
+ if ( ! fullDifferential && differentialLoadingNeeded ) {
111
+ entryPoints [ polyfillsChunkName ] . push ( path . join ( __dirname , '..' , 'jit-polyfills.js' ) ) ;
112
+ }
101
113
entryPoints [ polyfillsChunkName ] . push ( path . join ( __dirname , '..' , 'es5-jit-polyfills.js' ) ) ;
102
114
}
115
+ // If not performing a full differential build the polyfills need to be added to ES5 bundle
116
+ if ( ! fullDifferential && buildOptions . polyfills ) {
117
+ entryPoints [ polyfillsChunkName ] . push ( path . resolve ( root , buildOptions . polyfills ) ) ;
118
+ }
103
119
}
104
120
}
105
121
@@ -316,11 +332,17 @@ export function getCommonConfig(wco: WebpackConfigOptions): Configuration {
316
332
}
317
333
318
334
const terserOptions = {
319
- ecma : wco . supportES2015 ? 6 : 5 ,
335
+ // Use 5 if using bundle downleveling to ensure script bundles do not use ES2015+ features
336
+ // Script bundles are shared for differential loading
337
+ // Bundle processing will use the ES2015+ optimizations on the ES2015 bundles
338
+ ecma :
339
+ wco . supportES2015 &&
340
+ ( ! differentialLoadingNeeded || ( differentialLoadingNeeded && fullDifferential ) )
341
+ ? 6
342
+ : 5 ,
320
343
warnings : ! ! buildOptions . verbose ,
321
344
safari10 : true ,
322
345
output : {
323
- ascii_only : true ,
324
346
comments : false ,
325
347
webkit : true ,
326
348
} ,
@@ -339,7 +361,10 @@ export function getCommonConfig(wco: WebpackConfigOptions): Configuration {
339
361
global_defs : angularGlobalDefinitions ,
340
362
} ,
341
363
// We also want to avoid mangling on server.
342
- ...( buildOptions . platform == 'server' ? { mangle : false } : { } ) ,
364
+ // Name mangling is handled within the browser builder
365
+ mangle :
366
+ buildOptions . platform !== 'server' &&
367
+ ( ! differentialLoadingNeeded || ( differentialLoadingNeeded && fullDifferential ) ) ,
343
368
} ;
344
369
345
370
extraMinimizers . push (
0 commit comments