Registry / devops / service-worker-webpack

service-worker-webpack

JSON →
library1.0.0jsnpmunverified

A minimal Webpack plugin wrapper around Workbox (v6+) to generate a service worker that precaches static assets. Current stable version is 1.0.0, which follows semantic versioning. Works with Webpack 4 and 5, and ships TypeScript type definitions. Key differentiators: zero-config setup (just add the plugin), optional logging controls, and development mode support with proper cleanup of stale service workers.

npm install service-worker-webpack
INSTALL
IMPORT
SIG · SERVICE-WORKER-WEB
S
service-worker-webpack
devopsjavascriptv1.0.0
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 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

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

ServiceWorkerPlugin
const { ServiceWorkerPlugin } = require('service-worker-webpack');
import { ServiceWorkerPlugin } from 'service-worker-webpack';
This package does not export ESM; only CJS require() works. For projects using ESM, use dynamic import or transpile.
ServiceWorkerPlugin (default import)
const ServiceWorkerPlugin = require('service-worker-webpack').ServiceWorkerPlugin;
import ServiceWorkerPlugin from 'service-worker-webpack';
No default export exists; must use named export via require.
type ServiceWorkerPluginOptions
const { ServiceWorkerPlugin } = require('service-worker-webpack');
import type { ServiceWorkerPluginOptions } from 'service-worker-webpack';
TypeScript types are bundled but only accessible via the same require; no separate type export path.

Adds a service worker that precaches all output static assets using Workbox, with minimal configuration.

const path = require('path'); const { ServiceWorkerPlugin } = require('service-worker-webpack'); module.exports = { entry: './src/index.js', output: { filename: 'main.js', path: path.resolve(__dirname, 'dist'), }, plugins: [ new ServiceWorkerPlugin({ enableInDevelopment: false, enableWorkboxLogging: false, }), ], };
Debug
Known issues
gotchaWhen enableInDevelopment is false (default), the generated service worker in dev mode is a no-op that immediately unregisters any existing service worker. This can surprise developers who expect caching to work in development.
fix
Set enableInDevelopment: true in the plugin options during debugging, or accept that caching is disabled in development.
affects: >=1.0.0
gotchaWorkbox logging is verbose. By default, it logs in non-production mode; setting enableWorkboxLogging: false may still show logs if webpack mode is not 'production'.
fix
Explicitly set enableWorkboxLogging: false to suppress all workbox logs regardless of mode.
affects: >=1.0.0
gotchaThe plugin does not support custom service worker scripts via swSrc (unlike workbox-webpack-plugin). Users needing custom SW logic must use workbox-webpack-plugin directly.
fix
Switch to workbox-webpack-plugin if custom swSrc is required.
affects: >=1.0.0
breakingVersion 1.0.0 requires Webpack 4.37+ or 5.9+. Older Webpack versions (e.g., 4.36) are not supported.
fix
Upgrade webpack to ^4.37.0 || ^5.9.0.
affects: >=1.0.0
Errors
Common errors & fixes
Cannot find module 'service-worker-webpack'
Package not installed or installed incorrectly (not in devDependencies).
fix
npm install --save-dev service-worker-webpack
ServiceWorkerPlugin is not a constructor
Incorrect import: using ES import syntax on a CJS-only module.
fix
Change import to: const { ServiceWorkerPlugin } = require('service-worker-webpack');
TypeError: webpack.optimize.SplitChunksPlugin is not a constructor
This package does not export SplitChunksPlugin; user may have confused it with webpack's built-in plugin.
fix
Use webpack's optimize.splitChunks configuration instead.
Upgrade
Version history
1.0.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
8 hits · last 30 days
node
8
Resources
service-worker-webpack — npm install service-worker-webpack · libregistry