workbox-cli is the command-line interface for the Workbox library, a set of JavaScript modules for adding offline support to web applications. It streamlines the process of generating service workers and precaching assets, simplifying the integration of Workbox into projects without requiring complex custom build scripts. The current stable version is 7.4.0. Workbox CLI's release cadence generally aligns with the broader Workbox project, seeing frequent patch updates for dependency maintenance and security, with major versions introducing significant changes like Node.js version bumps. Its key differentiator is providing a user-friendly entry point for common Workbox use cases through a series of interactive wizards and declarative configuration files, abstracting away the underlying `workbox-build` module for a smoother developer experience.
npm install workbox-cliVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to use `workbox-cli` with a configuration file to generate a service worker that precaches assets and handles runtime caching for Google Fonts.
Upgrade your Node.js environment to version 20.0.0 or higher. For NVM users, run `nvm install 20 && nvm use 20`.
Always use the latest stable version of `workbox-cli` by regularly updating your installed package (`npm update workbox-cli` or `yarn upgrade workbox-cli`) or by using `npx workbox-cli` which fetches the latest version.
Ensure `globDirectory` points to the correct build output directory of your project, and `swDest` specifies a valid path within that directory (e.g., 'build/sw.js' if `globDirectory` is 'build/'). Always verify the paths relative to your project root.
Upgrade Node.js to version 20.0.0 or newer. Use `nvm install 20 && nvm use 20` or update your system's Node.js installation.
Either install it globally (`npm install -g workbox-cli`) or use `npx workbox-cli <command>` to execute the latest version without global installation.
Verify that the `globDirectory` property in your configuration file points to an actual, existing directory where your static assets are located.