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 // config goes here 17 }); 18 // do other things... 19}
Supported config keys
Key | Type |
---|---|
enable | boolean |
appCachePattern | string[] |
assetCachePattern | string[] |
skipFiles | string[] |
License
This package is MIT Licensed