8000 GitHub - vite-pwa/tanstack: Zero-config PWA for TanStack · GitHub
[go: up one dir, main page]

Skip to content
vite-pwaPublic

Repository files navigation

@vite-pwa/tanstack - Zero-config PWA for TanStack

Zero-config PWA for TanStack

NPM version NPM Downloads Docs & Guides
GitHub stars


Anthony Fu SVG sponsors image

🚀 Features

  • 📖 Documentation & guides
  • 👌 Zero-Config: sensible built-in default configs for common use cases
  • 🔩 Extensible: expose the full ability to customize the behavior of the plugin
  • 🦾 Type Strong: written in TypeScript
  • 🔌 Offline Support: generate service worker with offline support (via Workbox)
  • ⚡ Fully tree shakable: client virtual modules are strictly optimized for Dead Code Elimination.
  • 📄 Web Manifest: auto-inject Web App Manifest and PWA assets seamlessly.
  • 💬 Prompt for new content: built-in support for Vanilla JavaScript, Vue 3, React, Svelte, SolidJS and Preact
  • ⚙️ Stale-while-revalidate: automatic reload when new content is available
  • ✨ Static assets handling: configure static assets for offline support
  • 🐞 Development Support: debug your custom service worker logic as you develop your application
  • 🔍 Inspector: visually inspect your resolved configuration, web manifest and service worker during development, via middleware or DevFrame
  • 🧩 Modular: use the ready-to-use plugins or compose your own integration from the building blocks in @unplugin-pwa/core and @unplugin-pwa/vite
  • 📦 Universal Bundlers: native integration with Vite, Rolldown, Webpack (WIP), Rspack (WIP), and Rsbuild (WIP).
  • 🛠️ Meta-Frameworks: seamless integration with îles, SvelteKit, VitePress, Astro, Nuxt 3/4/5, React Router, TanStack and Next (WIP).
  • 💥 PWA Assets Generator: generate all the PWA assets from a single command and a single source image
  • 🚀 PWA Assets Integration: serving, generating and injecting PWA Assets on the fly in your application

📦 Install

npm i @vite-pwa/tanstack -D

# yarn
yarn add @vite-pwa/tanstack -D

# pnpm
pnpm add @vite-pwa/tanstack -D

🦄 Usage

This package provides two different plugins depending on your setup: a standard plugin for TanStack on Vite (SPA), and a specific plugin for TanStack Start powered by Nitro.

TanStack Start (with Nitro v3)

If you are using TanStack Start, use the TanStackNitroPWAPlugin variant.

⚠️ Important Requirements:

  • Nitro v3 RC: You must use the latest Nitro v3 Release Candidate 3.0.261029-rc (or newer) which includes the necessary lifecycle hook for the correct Service Worker pre-cache manifest generation.
  • Prerendering: You must explicitly enable prerendering for your routes in the nitro configuration (routeRules) and in the tanstackStart plugin to add offline support. Without pre-rendering (e.g., generating the index.html), offline support will not work as the entry points will be missing from the SW precache manifest.
// vite.config.ts
import { tanstackStart } from '@tanstack/react-start/plugin/vite'
import { TanStackNitroPWAPlugin } from '@vite-pwa/tanstack/vite/nitro'
import viteReact from '@vitejs/plugin-react'
import { nitro } from 'nitro/vite'
import { defineConfig } from 'vite'

export default defineConfig({
  plugins: [
    nitro({
      baseURL: '/',
      routeRules: {
        // Prerendering must be enabled for offline support to work
        '/': { prerender: true },
        '/about': { prerender: true },
      },
    }),
    tanstackStart({
      prerender: {
        enabled: true,
      },
    }),
    viteReact(),
    TanStackNitroPWAPlugin({
      // Your PWA options
      strategies: 'build-sw',
      registerType: 'autoUpdate',
      /* ... */
    }),
  ],
})

TanStack (Standalone Vite)

If you are building a standard Single Page Application with Vite and TanStack (without Nitro/SSR), use the TanStackVitePWAPlugin.

// vite.config.ts
import { TanStackVitePWAPlugin } from '@vite-pwa/tanstack'
import { defineConfig } from 'vite'

export default defineConfig({
  plugins: [
    // ... other plugins
    TanStackVitePWAPlugin({
      // Your PWA options
    }),
  ],
})

Read the 📖 documentation for a complete guide on how to configure and use this plugin.

👀 Full config

Check out the type declaration src/types.ts and the following links for more details.

📄 License

MIT License © 2026-PRESENT Anthony Fu

Releases

Packages

Contributors

Languages

0