mirror of
https://github.com/GuerillaStudio/souvenir.git
synced 2025-01-20 15:50:20 +00:00
fix(service worker): Add new Parcel build-in feature of SW
This commit is contained in:
parent
0133a60458
commit
418124de5c
3 changed files with 21 additions and 0 deletions
5
package-lock.json
generated
5
package-lock.json
generated
|
@ -1004,6 +1004,11 @@
|
|||
"nullthrows": "^1.1.1"
|
||||
}
|
||||
},
|
||||
"@parcel/service-worker": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/@parcel/service-worker/-/service-worker-2.0.0.tgz",
|
||||
"integrity": "sha512-fqFY2a/Y+ajbPiTQIriqeOG/dOJP6Ci8fWwcm1+hf5+QFm/PHcOHme9XL1PBVMPyfpGkE9h1VjK4F9mzV1I8Tg=="
|
||||
},
|
||||
"@parcel/source-map": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/@parcel/source-map/-/source-map-2.0.0.tgz",
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
"lint-fix": "eslint --ext .js,vue . --fix"
|
||||
},
|
||||
"dependencies": {
|
||||
"@parcel/service-worker": "^2.0.0",
|
||||
"folktale": "^2.3.2",
|
||||
"generic-pool": "^3.7.1",
|
||||
"gif-writer": "^0.9.3",
|
||||
|
|
15
service-worker.js
Normal file
15
service-worker.js
Normal file
|
@ -0,0 +1,15 @@
|
|||
import { manifest, version } from '@parcel/service-worker'
|
||||
|
||||
async function install () {
|
||||
const cache = await caches.open(version)
|
||||
await cache.addAll(manifest)
|
||||
}
|
||||
addEventListener('install', e => e.waitUntil(install()))
|
||||
|
||||
async function activate () {
|
||||
const keys = await caches.keys()
|
||||
await Promise.all(
|
||||
keys.map(key => key !== version && caches.delete(key))
|
||||
)
|
||||
}
|
||||
addEventListener('activate', e => e.waitUntil(activate()))
|
Loading…
Reference in a new issue