@@ -23,7 +23,7 @@ import {
2323} from 'webpack' ;
2424import { RawSource } from 'webpack-sources' ;
2525import { AssetPatternClass , ExtraEntryPoint } from '../../../browser/schema' ;
26- import { BuildBrowserFeatures } from '../../../utils/build-browser-features ' ;
26+ import { BuildBrowserFeatures , fullDifferential } from '../../../utils' ;
2727import { BundleBudgetPlugin } from '../../plugins/bundle-budget' ;
2828import { CleanCssWebpackPlugin } from '../../plugins/cleancss-webpack-plugin' ;
2929import { NamedLazyChunksPlugin } from '../../plugins/named-chunks-plugin' ;
@@ -59,19 +59,23 @@ export function getCommonConfig(wco: WebpackConfigOptions): Configuration {
5959 const entryPoints : { [ key : string ] : string [ ] } = { } ;
6060
6161 const targetInFileName = getEsVersionForFileName (
62- buildOptions . scriptTargetOverride ,
62+ fullDifferential ? buildOptions . scriptTargetOverride : tsConfig . options . target ,
6363 buildOptions . esVersionInFileName ,
6464 ) ;
6565
6666 if ( buildOptions . main ) {
6767 entryPoints [ 'main' ] = [ path . resolve ( root , buildOptions . main ) ] ;
6868 }
6969
70+ let differentialLoadingNeeded = false ;
7071 if ( wco . buildOptions . platform !== 'server' ) {
7172 const buildBrowserFeatures = new BuildBrowserFeatures (
7273 projectRoot ,
7374 tsConfig . options . target || ScriptTarget . ES5 ,
7475 ) ;
76+
77+ differentialLoadingNeeded = buildBrowserFeatures . isDifferentialLoadingNeeded ( ) ;
78+
7579 if ( ( buildOptions . scriptTargetOverride || tsConfig . options . target ) === ScriptTarget . ES5 ) {
7680 if (
7781 buildOptions . es5BrowserSupport ||
@@ -90,16 +94,28 @@ export function getCommonConfig(wco: WebpackConfigOptions): Configuration {
9094 : [ noModuleScript ] ;
9195 }
9296
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
9498 // 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' ;
98101
99102 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+ }
100108 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+ }
101113 entryPoints [ polyfillsChunkName ] . push ( path . join ( __dirname , '..' , 'es5-jit-polyfills.js' ) ) ;
102114 }
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+ }
103119 }
104120 }
105121
@@ -316,11 +332,17 @@ export function getCommonConfig(wco: WebpackConfigOptions): Configuration {
316332 }
317333
318334 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 ,
320343 warnings : ! ! buildOptions . verbose ,
321344 safari10 : true ,
322345 output : {
323- ascii_only : true ,
324346 comments : false ,
325347 webkit : true ,
326348 } ,
@@ -339,7 +361,10 @@ export function getCommonConfig(wco: WebpackConfigOptions): Configuration {
339361 global_defs : angularGlobalDefinitions ,
340362 } ,
341363 // 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 ) ) ,
343368 } ;
344369
345370 extraMinimizers . push (
0 commit comments