Alex Rickabaugh cb2e418d58
feat: add support for @angular/service-worker and manifest generation
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
2017-02-09 15:16:48 -08:00

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