Skip to content

Commit

Permalink
Revert "fix: build service workers in IIFE format" (#11400)
Browse files Browse the repository at this point in the history
* Revert "fix: build service workers in IIFE format (#11129)"

This reverts commit 5f052a3.

* better fix

* changeset

* remove format

---------

Co-authored-by: Rich Harris <rich.harris@vercel.com>
  • Loading branch information
Rich-Harris and Rich-Harris authored Dec 19, 2023
1 parent f8e3d8b commit 197e01f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .changeset/green-cycles-shake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

fix: prevent esbuild adding phantom exports to service worker
5 changes: 0 additions & 5 deletions .changeset/tricky-meals-perform.md

This file was deleted.

9 changes: 5 additions & 4 deletions packages/kit/src/exports/vite/build/build_service_worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,8 @@ export async function build_service_worker(
'service-worker': service_worker_entry_file
},
output: {
// default 'es' format would be nicer
// iife is workaround for https://github.com/vitejs/vite/issues/15379
format: 'iife',
entryFileNames: '[name].js',
// .mjs so that esbuild doesn't incorrectly inject `export` https://github.com/vitejs/vite/issues/15379
entryFileNames: 'service-worker.mjs',
assetFileNames: `${kit.appDir}/immutable/assets/[name].[hash][extname]`,
inlineDynamicImports: true
}
Expand All @@ -95,4 +93,7 @@ export async function build_service_worker(
}
}
});

// rename .mjs to .js to avoid incorrect MIME types with ancient webservers
fs.renameSync(`${out}/client/service-worker.mjs`, `${out}/client/service-worker.js`);
}

0 comments on commit 197e01f

Please sign in to comment.