ymchun:meteor-angular-service-worker

v1.1.2Published 7 years ago

This package has not had recent updates. Please investigate it's current state before committing to using it in your project.

Integrate new angular service worker into your meteor app

Installation

Add meteor package

$ meteor add ymchun:meteor-angular-service-worker

Install @angular/service-worker using npm

$ npm i @angular/service-worker

In app.module.ts just following angular's doc

1import { ServiceWorkerModule } from '@angular/service-worker';
2
3@NgModule({
4	// ...
5	imports: [
6		ServiceWorkerModule.register('/ngsw-worker.js', { enabled: Meteor.isProduction }),
7		// import other modules
8	],
9	// ...
10})
11export class AppModule {}

Configuration

On server-side, we can config the service worker and generating the ngsw.json file based on the config.

1import { Meteor } from 'meteor/meteor';
2
3declare module 'meteor/meteor' {
4	namespace Meteor {
5		let ServiceWorker: ServiceWorker;
6		interface ServiceWorker {
7			config: (options: object) => void;
8		}
9	}
10}
11
12// this is server
13if (Meteor.isServer) {
14	// set up service worker only on production
15	Meteor.ServiceWorker.config({
16		enable: Meteor.isProduction, // boolean, enable/disable service worker
17		cachePattern: [], // string array
18		skipFiles: [], // string array
19	});
20	// do other things...
21}

License

This package is MIT Licensed