mirror of
https://github.com/angular/angular-cli.git
synced 2025-05-22 23:15:56 +08:00
37 lines
1.0 KiB
TypeScript
37 lines
1.0 KiB
TypeScript
import { ExtraEntry, extraEntryParser } from '../models/webpack-configs/utils';
|
|
|
|
// Sort chunks according to a predefined order:
|
|
// inline, polyfills, all scripts, all styles, vendor, main
|
|
export function packageChunkSort(appConfig: any) {
|
|
let entryPoints = ['inline', 'polyfills'];
|
|
|
|
const pushExtraEntries = (extraEntry: ExtraEntry) => {
|
|
if (entryPoints.indexOf(extraEntry.entry) === -1) {
|
|
entryPoints.push(extraEntry.entry);
|
|
}
|
|
};
|
|
|
|
if (appConfig.scripts) {
|
|
extraEntryParser(appConfig.scripts, './', 'scripts').forEach(pushExtraEntries);
|
|
}
|
|
|
|
if (appConfig.styles) {
|
|
extraEntryParser(appConfig.styles, './', 'styles').forEach(pushExtraEntries);
|
|
}
|
|
|
|
entryPoints.push(...['vendor', 'main']);
|
|
|
|
return 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;
|
|
}
|
|
};
|
|
}
|