Registry / devops / rollup-plugin-workbox

rollup-plugin-workbox

JSON →
library8.1.3jsnpmunverified

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-workbox
INSTALL
IMPORT
SIG · ROLLUP-PLUGIN-WORK
R
rollup-plugin-workbox
devopsjavascriptv8.1.3
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18223 runs
build_error
glibc
node 18223 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

generateSW
import { generateSW } from 'rollup-plugin-workbox'
import generateSW from 'rollup-plugin-workbox'
Named export, not default. Also invalid: const { generateSW } = require('rollup-plugin-workbox') is valid CJS, but ESM is recommended.
injectManifest
import { injectManifest } from 'rollup-plugin-workbox'
import * as workbox from 'rollup-plugin-workbox'; const injectManifest = workbox.injectManifest;
Named export. Using namespace import works but is unnecessary.
generateSW (CJS)
const { generateSW } = require('rollup-plugin-workbox')
const generateSW = require('rollup-plugin-workbox')
CJS users must destructure. Module exports a named object, not default.

Generates a complete service worker using Workbox's generateSW mode during Rollup build. The plugin precaches all JS, CSS, HTML files in dist/.

// rollup.config.mjs import { generateSW } from 'rollup-plugin-workbox'; export default { input: 'src/main.js', output: { file: 'dist/bundle.js', format: 'esm', }, plugins: [ generateSW({ swDest: 'dist/sw.js', globDirectory: 'dist', globPatterns: ['**/*.{js,css,html}'], skipWaiting: true, clientsClaim: true, }), ], };
Debug
Known issues
gotchaThe workbox config object requires swDest and globDirectory. Omitting them will cause build failures.
fix
Always include swDest and globDirectory in the config object.
affects: >=0.0.0
deprecatedOld workbox-build versions (v5 and below) may have different config options. Ensure compatibility.
fix
Use workbox-build v6+ and refer to official workbox docs.
affects: >=8.0.0
gotchainjectManifest bundles the service worker via esbuild; source maps may not be preserved by default.
fix
Set esbuildOptions.sourcemap: true in injectManifest config if source maps are needed.
affects: >=8.0.0
gotchaThe plugin runs during the build hook; if used with watch mode, it may rerun unnecessarily.
fix
Use a conditional or separate rollup config for production builds only.
affects: >=0.0.0
gotchaWhen using injectManifest, the swSrc file must exist and be a valid JS file; otherwise esbuild bundling fails.
fix
Ensure swSrc is a valid JavaScript file with proper imports.
affects: >=0.0.0
Errors
Common errors & fixes
Error: The swDest option is required.
Missing 'swDest' in workbox config object passed to generateSW or injectManifest.
fix
Add 'swDest': 'path/to/sw.js' to the config object.
Could not resolve entry module '.../sw.js'
injectManifest swSrc path is incorrect or file does not exist.
fix
Check that swSrc file exists at the specified path relative to project root.
The 'globDirectory' property is required for injectManifest.
Missing 'globDirectory' in injectManifest config.
fix
Add 'globDirectory': 'dist' or your output directory.
Upgrade
Version history
8.1.3latest on npm
Audit
Dependencies
workbox-buildrequiredPeer dependency for generating service workers and precaching manifests.
esbuildoptionalUsed for bundling service worker code when using injectManifest mode.
rolluprequiredPeer dependency; Rollup plugin interface.
Agent activity
4 hits · last 30 days
node
4
Resources
rollup-plugin-workbox — npm install rollup-plugin-workbox · libregistry