-
-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: preCloseBundle hook #9326
feat: preCloseBundle hook #9326
Conversation
sorry: wrong changelist selected in my IDE, fixing lint |
the problem this solves is basically that two plugins both use parallel hooks but these hooks depend on each other. Alternative suggestions (some of which already have been discussed in chat): 1) the plugins depending on each other find a way to signal each other via
|
This PR is about the sequential plugin hack, I just renamed it so it doesn't sound drastic ;) . I guess Rollup should add configurable hooks, points 2) and 3) and this PR have the same problem, we need to hack Rollup. Point 3) I think it is almost impossible to implement it in the current state |
Description
Add a new
preCloseBundle
hook to allow run build plugins hooks between RollupwriteBundle
andcloseBundle
hooks.EDIT: we need it also in Vite 2 馃檹 .
I changed also
scripts/patchCJS.ts
module to allow build in Windows: I just changeprocess.exit()
call withprocess.exit(0)
: sent another PR for this.Additional context
Trying to integrate with SvelteKit the
vite-plugin-pwa
plugin, we have found a problem about a race condition using both plugins with Vite 3 (also with Vite 2, right now latest SvelteKit version will work only with Vite 3).SvelteKit uses the
writeBundle
to call theprerender
process (SSG). In thecloseBundle
hook, it calls theadapter
logic, the adapter gets theprerender
output and copy the content to theadapter
output folder (it can do more things).vite-plugin-pwa
usescloseBundle
hook in its build plugin to generate the service worker, it hasenforce: ' post'
, and so will be called by Vite/Rollup after SvelteKitcloseBundle
hook.We need to invert the
closeBundle
hook call, that's,vite-plugin-pwa
first and then SvelteKit`.We can reverse the order just changing the
vite-plugin-pwa
build plugin withenforce: 'pre'
, but then we have a race condition: since thecloseBundle
hook will be called in parallel, both plugins need to be called in asequential
order; why? because theadapter
needs to copy also the service worker generated by thevite-plugin-pwa
build plugin.Can we move the
vite-plugin-pwa
build plugin to thewriteBundle
hook: the answer is no; thevite-plugin-pwa
will need theprerender
output, and so we have the another race condition, since SvelteKit andvite-plugin-pwa
build plugin will run in parallel.What is the purpose of this pull request?
Before submitting the PR, please make sure you do the following
fixes #123
).