mirror of
https://github.com/angular/angular-cli.git
synced 2025-05-21 05:52:41 +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
17 lines
378 B
TypeScript
17 lines
378 B
TypeScript
import * as fs from 'fs';
|
|
|
|
export class StaticAssetPlugin {
|
|
|
|
constructor(private name: string, private contents: string) {}
|
|
|
|
apply(compiler: any): void {
|
|
compiler.plugin('emit', (compilation: any, cb: Function) => {
|
|
compilation.assets[this.name] = {
|
|
size: () => this.contents.length,
|
|
source: () => this.contents,
|
|
};
|
|
cb();
|
|
});
|
|
}
|
|
}
|