Skip to main content

integration

First added

8.2.0

About

Hooks of the build lifecycle.

Options

  • beforeBuildServiceWorker(options) — Allows you to run some logic before the service worker is built.
  • closeBundleOrder — Adjusts the application order of @serwist/vite's closeBundle hook.
  • configureOptions(viteOptions, options) — Allows you to configure the options of Serwist and Vite. Useful when there is a dependency between the two.

Usage

export default defineConfig({
  plugins: [
    // Other plugins...
    serwist({
      swSrc: "src/sw.ts",
      swDest: "sw.js",
      injectionPoint: "self.__SW_MANIFEST",
      rollupFormat: "iife",
      integration: {
        beforeBuildServiceWorker(options) {
          console.log(`Building service worker with options:`, options);
        },
        closeBundleOrder: "pre",
        configureOptions(viteConfig, options) {
          const clientOutDir = path.resolve(viteConfig.root, viteConfig.build.outDir);
          options.globDirectory = clientOutDir;
        },
      },
    }),
  ],
});