@@ -105,27 +105,27 @@ function getCommonConfig(wco) {
105
105
// determine hashing format
106
106
const hashFormat = utils_2 . getOutputHashFormat ( buildOptions . outputHashing || 'none' ) ;
107
107
// process global scripts
108
- if ( buildOptions . scripts . length > 0 ) {
109
- const globalScriptsByBundleName = utils_2 . normalizeExtraEntryPoints ( buildOptions . scripts , 'scripts' ) . reduce ( ( prev , curr ) => {
110
- const bundleName = curr . bundleName ;
111
- const resolvedPath = path . resolve ( root , curr . input ) ;
112
- const existingEntry = prev . find ( el => el . bundleName === bundleName ) ;
113
- if ( existingEntry ) {
114
- if ( existingEntry . inject && ! curr . inject ) {
115
- // All entries have to be lazy for the bundle to be lazy.
116
- throw new Error ( `The ${ curr . bundleName } bundle is mixing injected and non-injected scripts.` ) ;
117
- }
118
- existingEntry . paths . push ( resolvedPath ) ;
119
- }
120
- else {
121
- prev . push ( {
122
- bundleName,
123
- paths : [ resolvedPath ] ,
124
- inject : curr . inject ,
125
- } ) ;
108
+ const globalScriptsByBundleName = utils_2 . normalizeExtraEntryPoints ( buildOptions . scripts , 'scripts' ) . reduce ( ( prev , curr ) => {
109
+ const bundleName = curr . bundleName ;
110
+ const resolvedPath = path . resolve ( root , curr . input ) ;
111
+ const existingEntry = prev . find ( el => el . bundleName === bundleName ) ;
112
+ if ( existingEntry ) {
113
+ if ( existingEntry . inject && ! curr . inject ) {
114
+ // All entries have to be lazy for the bundle to be lazy.
115
+ throw new Error ( `The ${ curr . bundleName } bundle is mixing injected and non-injected scripts.` ) ;
126
116
}
127
- return prev ;
128
- } , [ ] ) ;
117
+ existingEntry . paths . push ( resolvedPath ) ;
118
+ }
119
+ else {
120
+ prev . push ( {
121
+ bundleName,
122
+ paths : [ resolvedPath ] ,
123
+ inject : curr . inject ,
124
+ } ) ;
125
+ }
126
+ return prev ;
127
+ } , [ ] ) ;
128
+ if ( globalScriptsByBundleName . length > 0 ) {
129
129
// Add a new asset for each entry.
130
130
globalScriptsByBundleName . forEach ( script => {
131
131
// Lazy scripts don't get a hash, otherwise they can't be loaded by name.
@@ -245,7 +245,8 @@ function getCommonConfig(wco) {
245
245
}
246
246
if ( buildOptions . aot ) {
247
247
// Also try to load AOT-only global definitions.
248
- const GLOBAL_DEFS_FOR_TERSER_WITH_AOT = require ( '@angular/compiler-cli' ) . GLOBAL_DEFS_FOR_TERSER_WITH_AOT ;
248
+ const GLOBAL_DEFS_FOR_TERSER_WITH_AOT = require ( '@angular/compiler-cli' )
249
+ . GLOBAL_DEFS_FOR_TERSER_WITH_AOT ;
249
250
if ( GLOBAL_DEFS_FOR_TERSER_WITH_AOT ) {
250
251
angularGlobalDefinitions = {
251
252
...angularGlobalDefinitions ,
@@ -254,27 +255,23 @@ function getCommonConfig(wco) {
254
255
}
255
256
}
256
257
const terserOptions = {
257
- // Use 5 if using bundle downleveling to ensure script bundles do not use ES2015+ features
258
- // Script bundles are shared for differential loading
259
- // Bundle processing will use the ES2015+ optimizations on the ES2015 bundles
260
- ecma : wco . supportES2015 &&
261
- ( ! differentialLoadingNeeded || ( differentialLoadingNeeded && utils_1 . fullDifferential ) )
262
- ? 6
263
- : 5 ,
264
258
warnings : ! ! buildOptions . verbose ,
265
259
safari10 : true ,
266
260
output : {
261
+ ecma : wco . supportES2015 ? 6 : 5 ,
267
262
comments : false ,
268
263
webkit : true ,
269
264
} ,
270
265
// On server, we don't want to compress anything. We still set the ngDevMode = false for it
271
266
// to remove dev code, and ngI18nClosureMode to remove Closure compiler i18n code
272
267
compress : buildOptions . platform == 'server'
273
268
? {
269
+ ecma : wco . supportES2015 ? 6 : 5 ,
274
270
global_defs : angularGlobalDefinitions ,
275
271
keep_fnames : true ,
276
272
}
277
273
: {
274
+ ecma : wco . supportES2015 ? 6 : 5 ,
278
275
pure_getters : buildOptions . buildOptimizer ,
279
276
// PURE comments work best with 3 passes.
280
277
// See https://github.com/webpack/webpack/issues/2899#issuecomment-317425926.
@@ -292,7 +289,29 @@ function getCommonConfig(wco) {
292
289
parallel : true ,
293
290
cache : true ,
294
291
extractComments : false ,
292
+ chunkFilter : ( chunk ) => ! globalScriptsByBundleName . some ( s => s . bundleName === chunk . name ) ,
295
293
terserOptions,
294
+ } ) ,
295
+ // Script bundles are fully optimized here in one step since they are never downleveled.
296
+ // They are shared between ES2015 & ES5 outputs so must support ES5.
297
+ new TerserPlugin ( {
298
+ sourceMap : scriptsSourceMap ,
299
+ parallel : true ,
300
+ cache : true ,
301
+ extractComments : false ,
302
+ chunkFilter : ( chunk ) => globalScriptsByBundleName . some ( s => s . bundleName === chunk . name ) ,
303
+ terserOptions : {
304
+ ...terserOptions ,
305
+ compress : {
306
+ ...terserOptions . compress ,
307
+ ecma : 5 ,
308
+ } ,
309
+ output : {
310
+ ...terserOptions . output ,
311
+ ecma : 5 ,
312
+ } ,
313
+ mangle : ! mangle_options_1 . manglingDisabled && buildOptions . platform !== 'server' ,
314
+ } ,
296
315
} ) ) ;
297
316
}
298
317
if ( wco . tsConfig . options . target !== undefined &&
0 commit comments