@@ -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
@@ -309,11 +325,17 @@ export function getCommonConfig(wco: WebpackConfigOptions): Configuration {
309
325
}
310
326
311
327
const terserOptions = {
312
- ecma : wco . supportES2015 ? 6 : 5 ,
328
+ // Use 5 if using bundle downleveling to ensure script bundles do not use ES2015+ features
329
+ // Script bundles are shared for differential loading
330
+ // Bundle processing will use the ES2015+ optimizations on the ES2015 bundles
331
+ ecma :
332
+ wco . supportES2015 &&
333
+ ( ! differentialLoadingNeeded || ( differentialLoadingNeeded && fullDifferential ) )
334
+ ? 6
335
+ : 5 ,
313
336
warnings : ! ! buildOptions . verbose ,
314
337
safari10 : true ,
315
338
output : {
316
- ascii_only : true ,
317
339
comments : false ,
318
340
webkit : true ,
319
341
} ,
@@ -332,7 +354,10 @@ export function getCommonConfig(wco: WebpackConfigOptions): Configuration {
332
354
global_defs : angularGlobalDefinitions ,
333
355
} ,
334
356
// We also want to avoid mangling on server.
335
- ...( buildOptions . platform == 'server' ? { mangle : false } : { } ) ,
357
+ // Name mangling is handled within the browser builder
358
+ mangle :
359
+ buildOptions . platform !== 'server' &&
360
+ ( ! differentialLoadingNeeded || ( differentialLoadingNeeded && fullDifferential ) ) ,
336
361
} ;
337
362
338
363
extraMinimizers . push (
0 commit comments