Skip to content

Commit

Permalink
include service-worker.js in manifest - fixes #3187
Browse files Browse the repository at this point in the history
  • Loading branch information
Rich-Harris committed Jan 27, 2022
1 parent 80233c2 commit ec867f9
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/brown-impalas-travel.md
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

Include service worker in manifest
1 change: 1 addition & 0 deletions packages/kit/src/core/build/index.js
Expand Up @@ -57,6 +57,7 @@ export async function build(config) {
const build_data = {
app_dir: config.kit.appDir,
manifest_data: options.manifest_data,
service_worker: options.service_worker_entry_file ? 'service_worker.js' : null, // TODO make file configurable?
client,
server,
static: options.manifest_data.assets.map((asset) => posixify(asset.file)),
Expand Down
7 changes: 6 additions & 1 deletion packages/kit/src/core/generate_manifest/index.js
Expand Up @@ -47,10 +47,15 @@ export function generate_manifest(
? (path) => `() => import('${path}')`
: (path) => `() => Promise.resolve().then(() => require('${path}'))`;

const assets = build_data.manifest_data.assets.map((asset) => asset.file);
if (build_data.service_worker) {
assets.push(build_data.service_worker);
}

// prettier-ignore
return `{
appDir: ${s(build_data.app_dir)},
assets: new Set(${s(build_data.manifest_data.assets.map(asset => asset.file))}),
assets: new Set(${s(assets)}),
_: {
mime: ${s(get_mime_lookup(build_data.manifest_data))},
entry: ${s(build_data.client.entry)},
Expand Down
1 change: 1 addition & 0 deletions packages/kit/types/internal.d.ts
Expand Up @@ -209,6 +209,7 @@ export interface ManifestData {
export interface BuildData {
app_dir: string;
manifest_data: ManifestData;
service_worker: string | null;
client: {
assets: OutputAsset[];
chunks: OutputChunk[];
Expand Down

0 comments on commit ec867f9

Please sign in to comment.