diff --git a/packages/runtimes/service-worker/src/ServiceWorkerRuntime.js b/packages/runtimes/service-worker/src/ServiceWorkerRuntime.js index 2aa01b0b72b..8df1327554f 100644 --- a/packages/runtimes/service-worker/src/ServiceWorkerRuntime.js +++ b/packages/runtimes/service-worker/src/ServiceWorkerRuntime.js @@ -24,18 +24,21 @@ export default (new Runtime({ } let manifest = []; + let precacheManifest = [] bundleGraph.traverseBundles(b => { if (b.bundleBehavior === 'inline' || b.id === bundle.id) { return; } manifest.push(urlJoin(b.target.publicUrl, b.name)); + precacheManifest.push({ url: urlJoin(b.target.publicUrl, b.name), revision: b.needsStableName ? b.hashReference : null }); }); let code = `import {_register} from '@parcel/service-worker'; const manifest = ${JSON.stringify(manifest)}; +const precacheManifest = ${JSON.stringify(precacheManifest)}; const version = ${JSON.stringify(bundle.hashReference)}; -_register(manifest, version); +_register(manifest, precacheManifest, version); `; return [ diff --git a/packages/utils/service-worker/service-worker.d.ts b/packages/utils/service-worker/service-worker.d.ts index e1f3e651b29..aed866680cd 100644 --- a/packages/utils/service-worker/service-worker.d.ts +++ b/packages/utils/service-worker/service-worker.d.ts @@ -1,2 +1,9 @@ +export declare interface PrecacheEntry { + integrity?: string; + url: string; + revision?: string | null; +} + export const manifest: string[]; +export const precacheManifest: PrecacheEntry[]; export const version: string; diff --git a/packages/utils/service-worker/service-worker.js b/packages/utils/service-worker/service-worker.js index 583f9171248..e53ce1aa47b 100644 --- a/packages/utils/service-worker/service-worker.js +++ b/packages/utils/service-worker/service-worker.js @@ -1,8 +1,10 @@ export let manifest = []; +export let precacheManifest = []; export let version = ''; // Called by the runtime. -export function _register(m, v) { +export function _register(m, pm, v) { manifest = m; + precacheManifest = pm; version = v; }