import { Plugin, ResolvedConfig } from 'vite'; import { InjectManifestOptions, GenerateSWOptions, ManifestEntry, RuntimeCaching } from 'workbox-build'; import { RollupOptions, OutputBundle } from 'rollup'; type InjectManifestVitePlugins = string[] | ((vitePluginIds: string[]) => string[]); type CustomInjectManifestOptions = InjectManifestOptions & { /** * Configure the format to use in the Rollup build. * * @default 'es' */ rollupFormat?: 'es' | 'iife'; /** * `Vite` plugin ids to use on `Rollup` build. * * **WARN**: this option is for advanced usage, beware, you can break your application build. * * @deprecated use `plugins` instead */ vitePlugins?: InjectManifestVitePlugins; /** * Since `v0.15.0` you can add plugins to build your service worker. * * When using `injectManifest` there are 2 builds, your application and the service worker. * If you're using custom configuration for your service worker (for example custom plugins) you can use this option to configure the service worker build. * Both configurations cannot be shared, and so you'll need to duplicate the configuration, with the exception of `define`. * * **WARN**: this option is for advanced usage, beware, you can break your application build. */ plugins?: Plugin[]; /** * Since `v0.15.0` you can add custom Rollup options to build your service worker: we expose the same configuration to build a worker using Vite. */ rollupOptions?: Omit; }; interface PWAIntegration { closeBundleOrder?: 'pre' | 'post' | null; configureOptions?: (viteOptions: ResolvedConfig, options: Partial) => void | Promise; } /** * Plugin options. */ interface VitePWAOptions { /** * Build mode * * @default process.env.NODE_ENV or "production" */ mode?: 'development' | 'production'; /** * @default 'public' */ srcDir?: string; /** * @default 'dist' */ outDir?: string; /** * @default 'sw.js' */ filename?: string; /** * @default 'manifest.webmanifest' */ manifestFilename?: string; /** * @default 'generateSW' */ strategies?: 'generateSW' | 'injectManifest'; /** * The scope to register the Service Worker * * @default same as `base` of Vite's config */ scope?: string; /** * Inject the service worker register inlined in the index.html * * With `auto` set, depends on whether you used the `import { registerSW } from 'virtual:pwa-register'` * it will do nothing or use the `script` mode * * `inline` - inject a simple register, inlined with the generated html * * `script` - inject