{"id":22291,"library":"rollup-plugin-workbox","title":"rollup-plugin-workbox","description":"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.","status":"active","version":"8.1.3","language":"javascript","source_language":"en","source_url":"https://github.com/modernweb-dev/web","tags":["javascript","rollup","service-worker","workbox","typescript"],"install":[{"cmd":"npm install rollup-plugin-workbox","lang":"bash","label":"npm"},{"cmd":"yarn add rollup-plugin-workbox","lang":"bash","label":"yarn"},{"cmd":"pnpm add rollup-plugin-workbox","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency for generating service workers and precaching manifests.","package":"workbox-build","optional":false},{"reason":"Used for bundling service worker code when using injectManifest mode.","package":"esbuild","optional":true},{"reason":"Peer dependency; Rollup plugin interface.","package":"rollup","optional":false}],"imports":[{"note":"Named export, not default. Also invalid: const { generateSW } = require('rollup-plugin-workbox') is valid CJS, but ESM is recommended.","wrong":"import generateSW from 'rollup-plugin-workbox'","symbol":"generateSW","correct":"import { generateSW } from 'rollup-plugin-workbox'"},{"note":"Named export. Using namespace import works but is unnecessary.","wrong":"import * as workbox from 'rollup-plugin-workbox'; const injectManifest = workbox.injectManifest;","symbol":"injectManifest","correct":"import { injectManifest } from 'rollup-plugin-workbox'"},{"note":"CJS users must destructure. Module exports a named object, not default.","wrong":"const generateSW = require('rollup-plugin-workbox')","symbol":"generateSW (CJS)","correct":"const { generateSW } = require('rollup-plugin-workbox')"}],"quickstart":{"code":"// rollup.config.mjs\nimport { generateSW } from 'rollup-plugin-workbox';\n\nexport default {\n  input: 'src/main.js',\n  output: {\n    file: 'dist/bundle.js',\n    format: 'esm',\n  },\n  plugins: [\n    generateSW({\n      swDest: 'dist/sw.js',\n      globDirectory: 'dist',\n      globPatterns: ['**/*.{js,css,html}'],\n      skipWaiting: true,\n      clientsClaim: true,\n    }),\n  ],\n};","lang":"javascript","description":"Generates a complete service worker using Workbox's generateSW mode during Rollup build. The plugin precaches all JS, CSS, HTML files in dist/."},"warnings":[{"fix":"Always include swDest and globDirectory in the config object.","message":"The workbox config object requires swDest and globDirectory. Omitting them will cause build failures.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Use workbox-build v6+ and refer to official workbox docs.","message":"Old workbox-build versions (v5 and below) may have different config options. Ensure compatibility.","severity":"deprecated","affected_versions":">=8.0.0"},{"fix":"Set esbuildOptions.sourcemap: true in injectManifest config if source maps are needed.","message":"injectManifest bundles the service worker via esbuild; source maps may not be preserved by default.","severity":"gotcha","affected_versions":">=8.0.0"},{"fix":"Use a conditional or separate rollup config for production builds only.","message":"The plugin runs during the build hook; if used with watch mode, it may rerun unnecessarily.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Ensure swSrc is a valid JavaScript file with proper imports.","message":"When using injectManifest, the swSrc file must exist and be a valid JS file; otherwise esbuild bundling fails.","severity":"gotcha","affected_versions":">=0.0.0"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Add 'swDest': 'path/to/sw.js' to the config object.","cause":"Missing 'swDest' in workbox config object passed to generateSW or injectManifest.","error":"Error: The swDest option is required."},{"fix":"Check that swSrc file exists at the specified path relative to project root.","cause":"injectManifest swSrc path is incorrect or file does not exist.","error":"Could not resolve entry module '.../sw.js'"},{"fix":"Add 'globDirectory': 'dist' or your output directory.","cause":"Missing 'globDirectory' in injectManifest config.","error":"The 'globDirectory' property is required for injectManifest."}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}