Skip to content

Commit 2090f64

Browse files
Charles LydingBrocco
Charles Lyding
authored andcommitted
feat(@angular/cli): improve common bundling performance
1 parent 66b2ed2 commit 2090f64

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed

packages/@angular/cli/models/webpack-configs/browser.ts

+5
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ export function getBrowserConfig(wco: WebpackConfigOptions) {
5959
new BaseHrefWebpackPlugin({
6060
baseHref: buildOptions.baseHref
6161
}),
62+
new webpack.optimize.CommonsChunkPlugin({
63+
async: 'common',
64+
children: true,
65+
minChunks: 2
66+
}),
6267
new webpack.optimize.CommonsChunkPlugin({
6368
minChunks: Infinity,
6469
name: 'inline'

tests/e2e/tests/misc/common-async.ts

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import {readdirSync} from 'fs';
2+
import {oneLine} from 'common-tags';
3+
4+
import {ng, npm} from '../../utils/process';
5+
import {addImportToModule} from '../../utils/ast';
6+
import {appendToFile} from '../../utils/fs';
7+
8+
9+
export default function() {
10+
let oldNumberOfFiles = 0;
11+
return Promise.resolve()
12+
.then(() => ng('build'))
13+
.then(() => oldNumberOfFiles = readdirSync('dist').length)
14+
.then(() => ng('generate', 'module', 'lazyA', '--routing'))
15+
.then(() => ng('generate', 'module', 'lazyB', '--routing'))
16+
.then(() => addImportToModule('src/app/app.module.ts', oneLine`
17+
RouterModule.forRoot([{ path: "lazyA", loadChildren: "./lazy-a/lazy-a.module#LazyAModule" }]),
18+
RouterModule.forRoot([{ path: "lazyB", loadChildren: "./lazy-b/lazy-b.module#LazyBModule" }])
19+
`, '@angular/router'))
20+
.then(() => ng('build'))
21+
.then(() => readdirSync('dist').length)
22+
.then(currentNumberOfDistFiles => {
23+
if (oldNumberOfFiles >= currentNumberOfDistFiles) {
24+
throw new Error('A bundle for the lazy module was not created.');
25+
}
26+
oldNumberOfFiles = currentNumberOfDistFiles;
27+
})
28+
.then(() => npm('install', 'moment'))
29+
.then(() => appendToFile('src/app/lazy-a/lazy-a.module.ts', `
30+
import * as moment from 'moment';
31+
console.log(moment);
32+
`))
33+
.then(() => ng('build'))
34+
.then(() => readdirSync('dist').length)
35+
.then(currentNumberOfDistFiles => {
36+
if (oldNumberOfFiles != currentNumberOfDistFiles) {
37+
throw new Error('The build contains a different number of files.');
38+
}
39+
})
40+
.then(() => appendToFile('src/app/lazy-b/lazy-b.module.ts', `
41+
import * as moment from 'moment';
42+
console.log(moment);
43+
`))
44+
.then(() => ng('build'))
45+
.then(() => readdirSync('dist').length)
46+
.then(currentNumberOfDistFiles => {
47+
if (oldNumberOfFiles >= currentNumberOfDistFiles) {
48+
throw new Error('A bundle for the common async module was not created.');
49+
}
50+
oldNumberOfFiles = currentNumberOfDistFiles;
51+
})
52+
// Check for AoT and lazy routes.
53+
.then(() => ng('build', '--aot'))
54+
.then(() => readdirSync('dist').length)
55+
.then(currentNumberOfDistFiles => {
56+
if (oldNumberOfFiles != currentNumberOfDistFiles) {
57+
throw new Error('AoT build contains a different number of files.');
58+
}
59+
});
60+
}

0 commit comments

Comments
 (0)