[]previous and next page

pwa

The pwa() Vite plugin.

The pwa() Vite plugin. After the client build it writes manifest.webmanifest (when manifest is given), the offline page, and sw.js into the client output. Nothing runs in vite dev.

Add it next to dusk() in vite.config.ts, link the manifest through the app's metadata, and call registerServiceWorker() of @shadow-js/dusk/features/pwa in the browser.

Import#

ts
import { pwa } from "@shadow-js/dusk/vite";

Signature#

ts
function pwa(options: PwaOptions = {}): Plugin

Parameters#

Name Description
options See PwaOptions.

Returns#

A Vite plugin.

Throws#

  • TypeError or RangeError for a bad option, and Error when a generated file would replace one from public/.

Examples#

ts
```ts
// vite.config.ts
import { dusk, pwa } from "@shadow-js/dusk/vite";

export default {
  plugins: [
    dusk(),
    pwa({
      manifest: { name: "Shop", short_name: "Shop", start_url: "/", display: "standalone", icons: [{ src: "/icon-512.png", sizes: "512x512", type: "image/png" }] },
      runtime: [{ pattern: "/api/products/*", strategy: "stale-while-revalidate", maxEntries: 30 }],
    }),
  ],
};