Skip to content

Commit 415c013

Browse files
author
Angular Builds
committed
b9f69d679 fix(@angular-devkit/build-angular): fully optimize script bundles with bundle downleveling
1 parent 0a4f5d5 commit 415c013

File tree

3 files changed

+54
-35
lines changed

3 files changed

+54
-35
lines changed

package.json

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
{
22
"name": "@angular-devkit/build-angular",
3-
"version": "0.900.0-next.3+22.f6fa3d7",
3+
"version": "0.900.0-next.3+23.b9f69d6",
44
"description": "Angular Webpack Build Facade",
55
"experimental": true,
66
"main": "src/index.js",
77
"typings": "src/index.d.ts",
88
"builders": "builders.json",
99
"dependencies": {
10-
"@angular-devkit/architect": "github:angular/angular-devkit-architect-builds#f6fa3d746",
11-
"@angular-devkit/build-optimizer": "github:angular/angular-devkit-build-optimizer-builds#f6fa3d746",
12-
"@angular-devkit/build-webpack": "github:angular/angular-devkit-build-webpack-builds#f6fa3d746",
13-
"@angular-devkit/core": "github:angular/angular-devkit-core-builds#f6fa3d746",
10+
"@angular-devkit/architect": "github:angular/angular-devkit-architect-builds#b9f69d679",
11+
"@angular-devkit/build-optimizer": "github:angular/angular-devkit-build-optimizer-builds#b9f69d679",
12+
"@angular-devkit/build-webpack": "github:angular/angular-devkit-build-webpack-builds#b9f69d679",
13+
"@angular-devkit/core": "github:angular/angular-devkit-core-builds#b9f69d679",
1414
"@babel/core": "7.5.5",
1515
"@babel/preset-env": "7.5.5",
16-
"@ngtools/webpack": "github:angular/ngtools-webpack-builds#f6fa3d746",
16+
"@ngtools/webpack": "github:angular/ngtools-webpack-builds#b9f69d679",
1717
"ajv": "6.10.2",
1818
"autoprefixer": "9.6.1",
1919
"browserslist": "4.7.0",

src/angular-cli-files/models/webpack-configs/common.js

+47-28
Original file line numberDiff line numberDiff line change
@@ -105,27 +105,27 @@ function getCommonConfig(wco) {
105105
// determine hashing format
106106
const hashFormat = utils_2.getOutputHashFormat(buildOptions.outputHashing || 'none');
107107
// 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.`);
126116
}
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) {
129129
// Add a new asset for each entry.
130130
globalScriptsByBundleName.forEach(script => {
131131
// Lazy scripts don't get a hash, otherwise they can't be loaded by name.
@@ -245,7 +245,8 @@ function getCommonConfig(wco) {
245245
}
246246
if (buildOptions.aot) {
247247
// 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;
249250
if (GLOBAL_DEFS_FOR_TERSER_WITH_AOT) {
250251
angularGlobalDefinitions = {
251252
...angularGlobalDefinitions,
@@ -254,27 +255,23 @@ function getCommonConfig(wco) {
254255
}
255256
}
256257
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,
264258
warnings: !!buildOptions.verbose,
265259
safari10: true,
266260
output: {
261+
ecma: wco.supportES2015 ? 6 : 5,
267262
comments: false,
268263
webkit: true,
269264
},
270265
// On server, we don't want to compress anything. We still set the ngDevMode = false for it
271266
// to remove dev code, and ngI18nClosureMode to remove Closure compiler i18n code
272267
compress: buildOptions.platform == 'server'
273268
? {
269+
ecma: wco.supportES2015 ? 6 : 5,
274270
global_defs: angularGlobalDefinitions,
275271
keep_fnames: true,
276272
}
277273
: {
274+
ecma: wco.supportES2015 ? 6 : 5,
278275
pure_getters: buildOptions.buildOptimizer,
279276
// PURE comments work best with 3 passes.
280277
// See https://github.com/webpack/webpack/issues/2899#issuecomment-317425926.
@@ -292,7 +289,29 @@ function getCommonConfig(wco) {
292289
parallel: true,
293290
cache: true,
294291
extractComments: false,
292+
chunkFilter: (chunk) => !globalScriptsByBundleName.some(s => s.bundleName === chunk.name),
295293
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+
},
296315
}));
297316
}
298317
if (wco.tsConfig.options.target !== undefined &&

uniqueId

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Tue Sep 10 2019 18:35:01 GMT+0000 (Coordinated Universal Time)
1+
Tue Sep 10 2019 18:36:40 GMT+0000 (Coordinated Universal Time)

0 commit comments

Comments
 (0)