Nuxt 3
WARNING
This PWA module can only be used with Vite.
Nuxt 3 Integration
vite-plugin-pwa provides the new @vite-pwa/nuxt integration that will allow you to use vite-plugin-pwa in your Nuxt 3 applications.
You will need to install @vite-pwa/nuxt using:
pnpm add -D @vite-pwa/nuxt
pnpm add -D @vite-pwa/nuxt
To update your project to use the new vite-plugin-pwa integration for Nuxt 3, you only need to change the Nuxt config file removing the vite-pwa-plugin plugin if present:
export default defineNuxtConfig({
  modules: ['@vite-pwa/nuxt'],
  pwa: {
    /* your pwa options */
  }
})
export default defineNuxtConfig({
  modules: ['@vite-pwa/nuxt'],
  pwa: {
    /* your pwa options */
  }
})
Using Nuxt 3 Plugin
@vite-pwa/nuxt will register a plugin exposing PWA stuff in your Nuxt 3 application via $pwa property.
The plugin will expose the following features:
- Prompt for update and offline ready via offlineReadyandofflineReadyproperties.
- Cancelling prompt for update application and offline via closePromptfunction.
- Update application when using prompt for updatebehaviour viaupdateServiceWorkerfunction.
- Intercepting beforeinstallpromptevent viashowInstallPromptproperty: this feature will prevent the browser to show the defaultInstall PWA Applicationprompt.
- Cancelling install prompt via cancelInstallfunction.
- Install PWA applicationvia- installfunction.
- Service worker registration status via swActivatedandregistrationErrorproperties.
- Service worker registration via getSWActivatedfunction.
You will need to activate pwa.installPrompt property in your Nuxt config file to enable beforeinstallprompt event interception: configure true or the key name used in local storage to store the beforeinstallprompt cancellation for your install prompt/widget.
Additionally, you can also configure periodic sync for updates, you can enable it via pwa.periodicSyncForUpdates property in your Nuxt config file: configure the interval in seconds in previous property.
You can disable this plugin by setting pwa.client.registerPlugin property to false in your Nuxt config file. In that case, you will need to import VanillaJS or Vue PWA virtual module in your application, previous properties will not be available.
INFO
This is the initial release of @vite-pwa/nuxt integration, we're working to improve it and add more features.
Registering Web Manifest
To register the PWA web manifest in your Nuxt 3 application, @vite-pwa/nuxt provides VitePwaManifest.ts functional component, you should add it to your app.vue or to all layouts files.
TIP
You can enable registerWebManifestInRouteRules property in PWA configuration to register the web manifest in Nitro routeRules property: useful for example if your application is deployed to Netlify.
Service Worker Without Precache
If you want to use old Nuxt PWA template in your service worker, check Service Worker Without Precache section.
Right now, you will need to create your service worker, we're working to provide a default service worker for Nuxt 3 applications without injection point.