The Workbox command line interface (contained in the
workbox-cli package) consists of a Node.js program called workbox that
can be run from a Windows, macOS, of UNIX-compatible command line
environment. Under the hood, workbox-cli wraps the workbox-build module,
and provides an easy way of integrating Workbox into a command line build
process, with flexible configurations.
Install the CLI
To install the CLI with Node, run the following command in your terminal:
npm install workbox-cli --global
CLI Modes
The CLI has four different modes:
wizard: A step-by-step guide to set up Workbox for your project.generateSW: Generates a complete service worker for you.injectManifest: Injects the assets to precache into your project.copyLibraries: Copy the Workbox libraries into a directory.
wizard
The Workbox wizard asks a series of questions about your local directory
setup and which files you want precached. Your answers are used to
generate a configuration file which can then be used when running in
generateSW mode.
Most developers will only need to run workbox wizard once, and you're free to manually customize the initial configuration file that's generated, using any of the supported build configuration options.
To start the wizard run:
npx workbox-cli wizard