forked from angular/angular-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpackage-chunk-sort.ts
37 lines (30 loc) · 1.07 KB
/
package-chunk-sort.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import { ExtraEntry, extraEntryParser } from '../models/webpack-configs/utils';
// Sort chunks according to a predefined order:
// inline, polyfills, all styles, vendor, main
export function packageChunkSort(appConfig: any) {
let entryPoints = ['inline', 'polyfills', 'sw-register'];
const pushExtraEntries = (extraEntry: ExtraEntry) => {
if (entryPoints.indexOf(extraEntry.entry) === -1) {
entryPoints.push(extraEntry.entry);
}
};
if (appConfig.styles) {
extraEntryParser(appConfig.styles, './', 'styles').forEach(pushExtraEntries);
}
entryPoints.push(...['vendor', 'main']);
function sort(left: any, right: any) {
let leftIndex = entryPoints.indexOf(left.names[0]);
let rightindex = entryPoints.indexOf(right.names[0]);
if (leftIndex > rightindex) {
return 1;
} else if (leftIndex < rightindex) {
return -1;
} else {
return 0;
}
}
// We need to list of entry points for the Ejected webpack config to work (we reuse the function
// defined above).
(sort as any).entryPoints = entryPoints;
return sort;
}