Setup guide · React (Vite)
Turn a React (Vite) app into an installable PWA (2026)
Vite + React PWA setup — manifest, service worker, install prompt. Works with SPA and multi-page Vite apps.
Key takeaways
- vite-plugin-pwa generates manifest and service worker at build time.
- For hand-rolled setups, /public is served at the origin root.
- React 18 strict mode double-invokes effects — guard your SW register.
Before you start
- Vite 4+
- React 18+
- HTTPS origin
manifest.webmanifest
{
"name": "Your product",
"short_name": "Product",
"start_url": "/",
"display": "standalone",
"background_color": "#ffffff",
"theme_color": "#111827",
"icons": [
{ "src": "/icon-192.png", "sizes": "192x192", "type": "image/png" },
{ "src": "/icon-512.png", "sizes": "512x512", "type": "image/png", "purpose": "any maskable" }
]
}Step-by-step for React (Vite)
- Step 1Install vite-plugin-pwa
Run `npm i -D vite-plugin-pwa` and add it to plugins in vite.config.ts.
- Step 2Configure the manifest
The plugin accepts the manifest inline and writes it at build time.
VitePWA({ registerType: 'autoUpdate', manifest: { name: 'Your product', theme_color: '#111827' } }) - Step 3Add the install popup
Paste the InstantPWA embed into index.html to skip writing prompt UI.
Minimal sw.js
// public/sw.js
self.addEventListener('install', (e) => self.skipWaiting());
self.addEventListener('activate', (e) => self.clients.claim());
self.addEventListener('fetch', () => {});Common React (Vite) gotchas
- React strict mode calls useEffect twice — always check for an existing registration before calling register.
- HMR does not reload the service worker. After changing sw.js, do a full reload.
FAQ
Do I need a native app if my React (Vite) site is a PWA?
No. Once your React (Vite) site meets the three PWA criteria (HTTPS, a manifest, a service worker), Chromium browsers offer to install it and iOS Safari 16.4+ supports the full standalone experience — including web push.
Will a service worker slow my React (Vite) site down?
Not measurably on first load. The worker installs asynchronously after the page becomes interactive. On repeat visits it typically improves LCP and TTFB because assets are served from cache.
Can I still deploy my React (Vite) site to Vercel, Netlify or Cloudflare?
Yes. Any static or edge host works — the manifest and service worker are plain files served from the origin. No build-time integration is required.
Skip the setup — drop in one line
InstantPWA handles the install prompt across iOS, Android and desktop. Free forever for one popup.
Get started free