|
1 |
| -export function packageChunkSort(packages: string[]) { |
2 |
| - return function sort(left: any, right: any) { |
3 |
| - let leftIndex = packages.indexOf(left.names[0]); |
4 |
| - let rightindex = packages.indexOf(right.names[0]); |
| 1 | +import { ExtraEntry, extraEntryParser } from '../models/webpack-build-utils'; |
5 | 2 |
|
6 |
| - if ( leftIndex < 0 || rightindex < 0) { |
7 |
| - // Unknown packages are loaded last |
8 |
| - return 1; |
| 3 | +// Sort chunks according to a predefined order: |
| 4 | +// inline, polyfills, all scripts, all styles, vendor, main |
| 5 | +export function packageChunkSort(appConfig: any) { |
| 6 | + let entryPoints = ['inline', 'polyfills']; |
| 7 | + |
| 8 | + const pushExtraEntries = (extraEntry: ExtraEntry) => { |
| 9 | + if (entryPoints.indexOf(extraEntry.entry) === -1) { |
| 10 | + entryPoints.push(extraEntry.entry); |
9 | 11 | }
|
| 12 | + }; |
| 13 | + |
| 14 | + if (appConfig.scripts) { |
| 15 | + extraEntryParser(appConfig.scripts, './', 'scripts').forEach(pushExtraEntries); |
| 16 | + } |
| 17 | + |
| 18 | + if (appConfig.styles) { |
| 19 | + extraEntryParser(appConfig.styles, './', 'styles').forEach(pushExtraEntries); |
| 20 | + } |
| 21 | + |
| 22 | + entryPoints.push(...['vendor', 'main']); |
| 23 | + |
| 24 | + return function sort(left: any, right: any) { |
| 25 | + let leftIndex = entryPoints.indexOf(left.names[0]); |
| 26 | + let rightindex = entryPoints.indexOf(right.names[0]); |
10 | 27 |
|
11 | 28 | if (leftIndex > rightindex) {
|
12 | 29 | return 1;
|
| 30 | + } else if (leftIndex < rightindex) { |
| 31 | + return -1; |
| 32 | + } else { |
| 33 | + return 0; |
13 | 34 | }
|
14 |
| - |
15 |
| - return -1; |
16 | 35 | };
|
17 | 36 | }
|
0 commit comments