On Vercel, the service worker is written outside the deployed output and precaches nothing
Problem
On Vercel, the PWA build writes sw.js where Vercel doesn't deploy it, and the service worker's precache list is empty.
vite.config.ts hard-codes VitePWA({ outDir: ".output/public" }) (added in #55). That's Nitro's public directory for the default node-server preset. Vercel builds use the vercel preset (Nitro detects Vercel automatically), and that preset writes client assets to .vercel/output/static. So the PWA plugin:
- searches the empty
.output/publicfor files to precache, and - writes
sw.jsandworkbox-*.jsinto.output/public, which Vercel doesn't deploy.registerSW.jsdoes land in.vercel/output/static, so it would point at a missing/sw.js.
Repro
rm -rf .output .vercel/output
NODE_ENV=production NITRO_PRESET=vercel bun run build
(NODE_ENV=production works around #88.)
PWA v1.3.0
mode generateSW
precache 3 entries (0.00 KiB)
files generated
.output/public/sw.js
.output/public/workbox-e190f46a.js
warnings
One of the glob patterns doesn't match any files. ... "globDirectory": ".../.output/public"
.vercel/output/static contains registerSW.js but no sw.js. CI builds with the node-server preset, where the client assets really are in .output/public, so the same config precaches 681 entries there.
Checked with a local NITRO_PRESET=vercel build of main (17ade4e), not against the live deployment. #87 (vite-plugin-pwa 2.0) doesn't change this: v2 still derives globDirectory and swDest from outDir.
Expected
On Vercel, the service worker is generated in the directory Vercel serves, its precache list covers the client assets, and /sw.js is deployed.
Possible fixes
- Point
outDirat the preset's public directory instead of hard-coding it, e.g..vercel/output/staticwhen building on Vercel. Under thevercelpreset, the client build already writes there, so the glob would find the assets. - After any fix, check that the
precacheline in the Vercel build log is non-empty and that/sw.jsis served.