Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

precache manifest #9940

Open
wants to merge 1 commit into
base: v2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion packages/runtimes/service-worker/src/ServiceWorkerRuntime.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 [
Expand Down
7 changes: 7 additions & 0 deletions packages/utils/service-worker/service-worker.d.ts
Original file line number Diff line number Diff line change
@@ -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;
4 changes: 3 additions & 1 deletion packages/utils/service-worker/service-worker.js
Original file line number Diff line number Diff line change
@@ -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;
}