-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Allow service workers to import assets #9285
Conversation
Vite has an option to disable that I believe. I also thought I'd mention that the PWA plugin just calls Rollup directly to build their service worker and doesn't use Vite to do it, so that's potentially another option - although it means options from the |
Options from
Any idea what it's called? I can't find it |
I think you can set |
Oh, interesting, I thought that only related to |
This should get a test but that'll be easier after merging #9250, so it can use the same mechanism |
🦋 Changeset detectedLatest commit: f0aec4e The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Added a test, I think this is ready to go |
Can we set a rollup option to inline the dynamic import? I imagine that's what |
that was done in a34f855 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm as long as this works when base
is set
@@ -64,16 +63,16 @@ export async function build_service_worker( | |||
); | |||
|
|||
await vite.build({ | |||
base: assets_base(kit), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a bit suspicious that we were using the base before and are not now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we use location.href
, so the service worker is portable. this is more robust than letting vite hard-code stuff
Closes #9256. I don't know if this is a good idea or not but thought I'd try. Basically,
build.lib
always results in a single JavaScript file with everything inlined, whereasbuild.rollupOptions
gives us more flexibility. But I'm not sure if it creates other problems. For example, a dynamicimport(...)
will be inlined at the moment; with this PR it will keep the dynamic import (which won't work in a non-module service worker, and we can't use module service workers yet) and will inject Vite's module preloading logic, which won't work because it referencesdocument
.There might be a combination of configuration options that gives us the bits we need without the bits we don't — for now I'm just going to leave this here
Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
Tests
pnpm test
and lint the project withpnpm lint
andpnpm check
Changesets
pnpm changeset
and following the prompts. Changesets that add features should beminor
and those that fix bugs should bepatch
. Please prefix changeset messages withfeat:
,fix:
, orchore:
.