angular-cli/packages/@angular/cli/utilities/package-chunk-sort.ts
Filipe Silva e8f27f029a feat(@angular/cli): support sourcemaps and minification in scripts
Adds sourcemap and minification to javascript added via the `scripts` array in `.angular-cli.json`.

`script-loader` is no longer used, which should help with CSP since it used `eval`.

Scripts will no longer appear in the console output for `ng build`, as they are now assets instead of webpack entry points.

It's no longer possible to have the `output` property of both a `scripts` and a `styles` entry pointing to the same file. This wasn't officially supported or listed in the docs, but used to be possible.

Fix #2796
Fix #7226
Fix #7290

Related to #6872
2017-08-17 16:38:35 -04:00

38 lines
1.1 KiB
TypeScript

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;
}