ionic-team / ionic-pwa-toolkit

Build lightning fast Progressive Web Apps with zero config and best practices built-in. Go from zero to production ready with Ionic and Stencil (Web Components).
MIT License
633 stars 74 forks source link

service worker - not being generated #110

Open ashishtilara opened 4 years ago

ashishtilara commented 4 years ago

when I run

npm init stencil ionic-pwa

the generated code doesn't have service worker file, or package.json doesn't have any mention of start.sw in scripts, is there anything I am missing?

rafaelbatistamarcilio commented 4 years ago

@ashishtilara there is a file called stencil.config.ts with the following code:

` import { Config } from '@stencil/core';

// https://stenciljs.com/docs/config

export const config: Config = { outputTargets: [{ type: 'www', serviceWorker: null }], globalScript: 'src/global/app.ts', globalStyle: 'src/global/app.css' }; `

If you press CTRL + left mouse button you will see that exists a ServiceWorkerConfig that you can use.

I just change my stencil.config.ts to the following code and the build generate a sw.js

import { Config } from '@stencil/core';

// https://stenciljs.com/docs/config

export const config: Config = { outputTargets: [{ type: 'www', serviceWorker: { cacheId:'v1', } }], globalScript: 'src/global/app.ts', globalStyle: 'src/global/app.css' }; It will be nice if Stencil team improves the service worker docs to give us examples of configurations and examples of service worker features like push notifications and backgroud sync