Skip to content

Commit 788c8f9

Browse files
filipesilvaclydin
authored andcommitted
fix(@angular/cli): show only changed chunks on build
For projects with a lot of lazy modules the rebuild messages can easily fill the whole console window. This PR shows only chunks that changed instead of showing all chunks. Before: ``` $ ng serve ** NG Live Development Server is listening on localhost:4200, open your browser on http://localhost:4200/ ** Date: 2017-12-14T14:56:13.707Z Hash: 7490b2942c48ffcf0f0f Time: 7317ms chunk {inline} inline.bundle.js (inline) 5.79 kB [entry] [rendered] chunk {main} main.bundle.js (main) 725 kB [initial] [rendered] chunk {polyfills} polyfills.bundle.js (polyfills) 577 kB [initial] [rendered] chunk {styles} styles.bundle.js (styles) 35 kB [initial] [rendered] chunk {vendor} vendor.bundle.js (vendor) 6.45 MB [initial] [rendered] webpack: Compiled successfully. webpack: Compiling... Date: 2017-12-14T14:56:17.054Z Hash: dbb03cc0994e8bf69e76 Time: 310ms chunk {inline} inline.bundle.js (inline) 5.79 kB [entry] chunk {main} main.bundle.js (main) 725 kB [initial] [rendered] chunk {polyfills} polyfills.bundle.js (polyfills) 577 kB [initial] chunk {styles} styles.bundle.js (styles) 35 kB [initial] chunk {vendor} vendor.bundle.js (vendor) 6.45 MB [initial] webpack: Compiled successfully. webpack: Compiling... Date: 2017-12-14T14:56:20.290Z Hash: fe53cbcd529dd2508cfc Time: 267ms chunk {inline} inline.bundle.js (inline) 5.79 kB [entry] chunk {main} main.bundle.js (main) 725 kB [initial] chunk {polyfills} polyfills.bundle.js (polyfills) 577 kB [initial] [rendered] chunk {styles} styles.bundle.js (styles) 35 kB [initial] chunk {vendor} vendor.bundle.js (vendor) 6.45 MB [initial] webpack: Compiled successfully. ``` After: ``` $ ng serve ** NG Live Development Server is listening on localhost:4200, open your browser on http://localhost:4200/ ** Date: 2017-12-14T14:53:40.216Z Hash: 44065f5ec5c4c8cf884a Time: 7312ms chunk {inline} inline.bundle.js (inline) 5.79 kB [entry] [rendered] chunk {main} main.bundle.js (main) 724 kB [initial] [rendered] chunk {polyfills} polyfills.bundle.js (polyfills) 576 kB [initial] [rendered] chunk {styles} styles.bundle.js (styles) 35 kB [initial] [rendered] chunk {vendor} vendor.bundle.js (vendor) 6.45 MB [initial] [rendered] webpack: Compiled successfully. webpack: Compiling... Date: 2017-12-14T14:53:42.089Z Hash: 492a7350b12ec1557b61 Time: 241ms chunk {main} main.bundle.js (main) 725 kB [initial] [rendered] 4 unchanged chunks webpack: Compiled successfully. webpack: Compiling... Date: 2017-12-14T14:53:49.762Z Hash: 7490b2942c48ffcf0f0f Time: 296ms chunk {polyfills} polyfills.bundle.js (polyfills) 577 kB [initial] [rendered] 4 unchanged chunks webpack: Compiled successfully. ``` Fix #8621
1 parent aa90e42 commit 788c8f9

File tree

2 files changed

+23
-15
lines changed

2 files changed

+23
-15
lines changed

packages/@angular/cli/utilities/stats.ts

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,9 @@ export function statsToString(json: any, statsConfig: any) {
2626
const g = (x: string) => colors ? bold(green(x)) : x;
2727
const y = (x: string) => colors ? bold(yellow(x)) : x;
2828

29-
return rs(stripIndents`
30-
Date: ${w(new Date().toISOString())}
31-
Hash: ${w(json.hash)}
32-
Time: ${w('' + json.time)}ms
33-
${json.chunks.map((chunk: any) => {
29+
const changedChunksStats = json.chunks
30+
.filter((chunk: any) => chunk.rendered)
31+
.map((chunk: any) => {
3432
const asset = json.assets.filter((x: any) => x.name == chunk.files[0])[0];
3533
const size = asset ? ` ${_formatSize(asset.size)}` : '';
3634
const files = chunk.files.join(', ');
@@ -41,8 +39,24 @@ export function statsToString(json: any, statsConfig: any) {
4139
.join('');
4240

4341
return `chunk {${y(chunk.id)}} ${g(files)}${names}${size} ${initial}${flags}`;
44-
}).join('\n')}
45-
`);
42+
});
43+
44+
const unchangedChunkNumber = json.chunks.length - changedChunksStats.length;
45+
46+
if (unchangedChunkNumber > 0) {
47+
return rs(stripIndents`
48+
Date: ${w(new Date().toISOString())} • Hash: ${w(json.hash)} • Time: ${w('' + json.time)}ms
49+
${unchangedChunkNumber} unchanged chunks
50+
${changedChunksStats.join('\n')}
51+
`);
52+
} else {
53+
return rs(stripIndents`
54+
Date: ${w(new Date().toISOString())}
55+
Hash: ${w(json.hash)}
56+
Time: ${w('' + json.time)}ms
57+
${changedChunksStats.join('\n')}
58+
`);
59+
}
4660
}
4761

4862
export function statsWarningsToString(json: any, statsConfig: any) {

tests/e2e/tests/basic/rebuild.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,9 @@ export default function() {
2020
return Promise.resolve();
2121
}
2222

23-
let oldNumberOfChunks = 0;
24-
const chunkRegExp = /chunk\s+\{/g;
23+
const lazyChunkRegExp = /lazy\.module\.chunk\.js/g;
2524

2625
return execAndWaitForOutputToMatch('ng', ['serve'], validBundleRegEx)
27-
// Count the bundles.
28-
.then(({ stdout }) => {
29-
oldNumberOfChunks = stdout.split(chunkRegExp).length;
30-
})
3126
// Add a lazy module.
3227
.then(() => ng('generate', 'module', 'lazy', '--routing'))
3328
// Should trigger a rebuild with a new bundle.
@@ -65,8 +60,7 @@ export default function() {
6560
// Count the bundles.
6661
.then((results) => {
6762
const stdout = results[0].stdout;
68-
let newNumberOfChunks = stdout.split(chunkRegExp).length;
69-
if (oldNumberOfChunks >= newNumberOfChunks) {
63+
if (!lazyChunkRegExp.test(stdout)) {
7064
throw new Error('Expected webpack to create a new chunk, but did not.');
7165
}
7266
})

0 commit comments

Comments
 (0)