With workbox-sw, you can load the Workbox runtime from a CDN or locally, and compose your own service worker. If that describes your situation, it's still possible to use Workbox with the workbox-sw module. This article assumes your project has a build process, but your project, in fact, may not. In cases like these, you can always fall back to the methods discussed in this article. It's worth noting that these framework-specific integrations of Workbox may restrict your ability to configure Workbox in the way you want. Different framework integrations with Workbox are covered later in a later article. For example, create-react-app ships with Workbox by default. However, it's possible to use Workbox within a specific framework if it makes development easier. # Using a frameworkĮverything covered up this point focuses on using Workbox regardless of one's framework preferences. In particular, you don't need to-nor can you-specify a globDirectory option for GenerateSW as webpack already knows where your production assets are bundled. The options you pass to either GenerateSW or InjectManifest aren't the same as generateSW or injectManifest, but there's significant overlap. Other webpack config options omitted for brevity. When using workbox-build, instead of specifying options via a workbox-config.js file, you'll use the generateSW or injectManifest methods directly as part of a Node script, passing in a similar set of options: // build-sw.mjs Workbox-cli is a wrapper around the workbox-build module, and an alternative is to use workbox-builddirectly. The CLI's help text has more information and examples of usage. Once your configuration file has been created, the CLI can run either generateSW or injectManifest methods for you. It will look something like: // A config for `generateSW` The wizard will ask a few questions, and the answers to those questions will be used to set up a project with a workbox-config.js file that you can customize to suit your needs. To start using the CLI, run the wizard with npx workbox wizard. If you're looking for the lowest possible barrier to entry with Workbox, the CLI is for you: npm install workbox-cli -save-dev In order to know which of these options is the best fit, let's take a quick look at each one. These are all fine choices when you don't want to tie your Workbox-powered service worker to a particular framework.
0 Comments
Leave a Reply. |