Rollup plugin that builds a service worker with Workbox as part of your Rollup build. Current stable version is 8.1.3, released under the @web scope on npm. Enables integration of Workbox's generateSW and injectManifest modes directly into Rollup's build pipeline, with optional console output customization and automatic bundling of service worker code via esbuild when using injectManifest. Key differentiator: seamless Rollup integration vs standalone workbox-build CLI or webpack plugin. Part of the modernweb-dev/web project. Releases are patch-level; no major changes in recent history. Ships TypeScript definitions.
npm install rollup-plugin-workboxVerified import paths — ran on the pinned version, not inferred.
Generates a complete service worker using Workbox's generateSW mode during Rollup build. The plugin precaches all JS, CSS, HTML files in dist/.
Always include swDest and globDirectory in the config object.
Use workbox-build v6+ and refer to official workbox docs.
Set esbuildOptions.sourcemap: true in injectManifest config if source maps are needed.
Use a conditional or separate rollup config for production builds only.
Ensure swSrc is a valid JavaScript file with proper imports.
Add 'swDest': 'path/to/sw.js' to the config object.
Check that swSrc file exists at the specified path relative to project root.
Add 'globDirectory': 'dist' or your output directory.