@@ -14,13 +14,13 @@ const path = require("path");
1414const typescript_1 = require ( "typescript" ) ;
1515const webpack_1 = require ( "webpack" ) ;
1616const webpack_sources_1 = require ( "webpack-sources" ) ;
17- const build_browser_features_1 = require ( "../../../utils/build-browser-features " ) ;
17+ const utils_1 = require ( "../../../utils" ) ;
1818const bundle_budget_1 = require ( "../../plugins/bundle-budget" ) ;
1919const cleancss_webpack_plugin_1 = require ( "../../plugins/cleancss-webpack-plugin" ) ;
2020const named_chunks_plugin_1 = require ( "../../plugins/named-chunks-plugin" ) ;
2121const scripts_webpack_plugin_1 = require ( "../../plugins/scripts-webpack-plugin" ) ;
2222const find_up_1 = require ( "../../utilities/find-up" ) ;
23- const utils_1 = require ( "./utils" ) ;
23+ const utils_2 = require ( "./utils" ) ;
2424const ProgressPlugin = require ( 'webpack/lib/ProgressPlugin' ) ;
2525const CircularDependencyPlugin = require ( 'circular-dependency-plugin' ) ;
2626const TerserPlugin = require ( 'terser-webpack-plugin' ) ;
@@ -38,12 +38,14 @@ function getCommonConfig(wco) {
3838 // tslint:disable-next-line:no-any
3939 const extraPlugins = [ ] ;
4040 const entryPoints = { } ;
41- const targetInFileName = utils_1 . getEsVersionForFileName ( buildOptions . scriptTargetOverride , buildOptions . esVersionInFileName ) ;
41+ const targetInFileName = utils_2 . getEsVersionForFileName ( utils_1 . fullDifferential ? buildOptions . scriptTargetOverride : tsConfig . options . target , buildOptions . esVersionInFileName ) ;
4242 if ( buildOptions . main ) {
4343 entryPoints [ 'main' ] = [ path . resolve ( root , buildOptions . main ) ] ;
4444 }
45+ let differentialLoadingNeeded = false ;
4546 if ( wco . buildOptions . platform !== 'server' ) {
46- const buildBrowserFeatures = new build_browser_features_1 . BuildBrowserFeatures ( projectRoot , tsConfig . options . target || typescript_1 . ScriptTarget . ES5 ) ;
47+ const buildBrowserFeatures = new utils_1 . BuildBrowserFeatures ( projectRoot , tsConfig . options . target || typescript_1 . ScriptTarget . ES5 ) ;
48+ differentialLoadingNeeded = buildBrowserFeatures . isDifferentialLoadingNeeded ( ) ;
4749 if ( ( buildOptions . scriptTargetOverride || tsConfig . options . target ) === typescript_1 . ScriptTarget . ES5 ) {
4850 if ( buildOptions . es5BrowserSupport ||
4951 ( buildOptions . es5BrowserSupport === undefined && buildBrowserFeatures . isEs5SupportNeeded ( ) ) ) {
@@ -59,15 +61,26 @@ function getCommonConfig(wco) {
5961 ? [ ...buildOptions . scripts , noModuleScript ]
6062 : [ noModuleScript ] ;
6163 }
62- // For differential loading we don't need to generate a seperate polyfill file
64+ // For full build differential loading we don't need to generate a seperate polyfill file
6365 // because they will be loaded exclusivly based on module and nomodule
64- const polyfillsChunkName = buildBrowserFeatures . isDifferentialLoadingNeeded ( )
65- ? 'polyfills'
66- : 'polyfills-es5' ;
66+ const polyfillsChunkName = utils_1 . fullDifferential && differentialLoadingNeeded ? 'polyfills' : 'polyfills-es5' ;
6767 entryPoints [ polyfillsChunkName ] = [ path . join ( __dirname , '..' , 'es5-polyfills.js' ) ] ;
68+ if ( ! utils_1 . fullDifferential && differentialLoadingNeeded ) {
69+ // Add zone.js legacy support to the es5 polyfills
70+ // This is a noop execution-wise if zone-evergreen is not used.
71+ entryPoints [ polyfillsChunkName ] . push ( 'zone.js/dist/zone-legacy' ) ;
72+ }
6873 if ( ! buildOptions . aot ) {
74+ // If not performing a full differential build the JIT polyfills need to be added to ES5
75+ if ( ! utils_1 . fullDifferential && differentialLoadingNeeded ) {
76+ entryPoints [ polyfillsChunkName ] . push ( path . join ( __dirname , '..' , 'jit-polyfills.js' ) ) ;
77+ }
6978 entryPoints [ polyfillsChunkName ] . push ( path . join ( __dirname , '..' , 'es5-jit-polyfills.js' ) ) ;
7079 }
80+ // If not performing a full differential build the polyfills need to be added to ES5 bundle
81+ if ( ! utils_1 . fullDifferential && buildOptions . polyfills ) {
82+ entryPoints [ polyfillsChunkName ] . push ( path . resolve ( root , buildOptions . polyfills ) ) ;
83+ }
7184 }
7285 }
7386 if ( buildOptions . polyfills ) {
@@ -89,10 +102,10 @@ function getCommonConfig(wco) {
89102 } ) ) ;
90103 }
91104 // determine hashing format
92- const hashFormat = utils_1 . getOutputHashFormat ( buildOptions . outputHashing || 'none' ) ;
105+ const hashFormat = utils_2 . getOutputHashFormat ( buildOptions . outputHashing || 'none' ) ;
93106 // process global scripts
94107 if ( buildOptions . scripts . length > 0 ) {
95- const globalScriptsByBundleName = utils_1 . normalizeExtraEntryPoints ( buildOptions . scripts , 'scripts' ) . reduce ( ( prev , curr ) => {
108+ const globalScriptsByBundleName = utils_2 . normalizeExtraEntryPoints ( buildOptions . scripts , 'scripts' ) . reduce ( ( prev , curr ) => {
96109 const bundleName = curr . bundleName ;
97110 const resolvedPath = path . resolve ( root , curr . input ) ;
98111 const existingEntry = prev . find ( el => el . bundleName === bundleName ) ;
@@ -240,11 +253,16 @@ function getCommonConfig(wco) {
240253 }
241254 }
242255 const terserOptions = {
243- ecma : wco . supportES2015 ? 6 : 5 ,
256+ // Use 5 if using bundle downleveling to ensure script bundles do not use ES2015+ features
257+ // Script bundles are shared for differential loading
258+ // Bundle processing will use the ES2015+ optimizations on the ES2015 bundles
259+ ecma : wco . supportES2015 &&
260+ ( ! differentialLoadingNeeded || ( differentialLoadingNeeded && utils_1 . fullDifferential ) )
261+ ? 6
262+ : 5 ,
244263 warnings : ! ! buildOptions . verbose ,
245264 safari10 : true ,
246265 output : {
247- ascii_only : true ,
248266 comments : false ,
249267 webkit : true ,
250268 } ,
@@ -262,7 +280,9 @@ function getCommonConfig(wco) {
262280 global_defs : angularGlobalDefinitions ,
263281 } ,
264282 // We also want to avoid mangling on server.
265- ...( buildOptions . platform == 'server' ? { mangle : false } : { } ) ,
283+ // Name mangling is handled within the browser builder
284+ mangle : buildOptions . platform !== 'server' &&
285+ ( ! differentialLoadingNeeded || ( differentialLoadingNeeded && utils_1 . fullDifferential ) ) ,
266286 } ;
267287 extraMinimizers . push ( new TerserPlugin ( {
268288 sourceMap : scriptsSourceMap ,
0 commit comments