mirror of
https://github.com/angular/angular-cli.git
synced 2025-05-22 15:02:11 +08:00
Adds the flag 'serviceWorker' to angular-cli.json that enables support for @angular/service-worker. When this flag is true, production builds will be set up with a service worker. A ngsw-manifest.json file will be generated (or augmented) in the dist/ root, and the service worker script will be copied there. A short script will be added to index.html to register the service worker. @angular/service-worker is a dependency of @angular/cli, but not of generated projects. It is desirable for users to be able to update the version of @angular/service-worker used in their apps independently of the CLI version. Thus, the CLI will error if serviceWorker=true but @angular/service-worker is not installed in the application's node_modules, as it pulls all the service worker scripts from there. If the flag is false the effect on the CLI is minimal - the webpack plugins associated with the SW are not even require()'d. Closes #4544
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', 'sw-register'];
|
|
|
|
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;
|
|
}
|
|
};
|
|
}
|