A Parcel plugin for generating a service worker that precaches resources.
npm install --save-dev parcel-plugin-sw-precache
You DON'T have to configure anything to get it work. It just works as you expected after you installed.
Every time you build resources with Parcel, it will generate a service-worker.js
file for you.
Internally it is using sw-precache
If you want to configure sw-precache
, you can supply the configs by adding them in your package.json
within the key sw-precache
. See all available options at: https://github.com/GoogleChromeLabs/sw-precache#options-parameter
Additionally this plugin have the option "additionalCodeFile" if you want to add anything to your service-worker.js (for example a new event-handler). Add a filename relative to the entrypoint specified to Parcel.
For example:
{
"name": "my-project",
"version": "0.1.0",
...
// my sw-precache configs
"sw-precache": {
"maximumFileSizeToCacheInBytes": 10485760,
"additionalCodeFile": "addSome.js"
}
}
Note: only files with the following extensions will be added to the precache :
js, html, css, png, jpg, gif, svg, eot, ttf, woff, woff2, ogg, wav, mp3, wasm, webp, pdf
MIT