parcel-plugin-workbox-rev
An updated plugin for Parcel to generate a service worker with Workbox, derived from Anders Dahnielson's parcel-plugin-workbox.
Install
You can either install by running yarn (recommended)
yarn add parcel-plugin-workbox-rev --dev
or use npm
npm install parcel-plugin-workbox-rev --save-dev
Usage
When you build resources with Parcel, the plugin will generate a service worker sw.js
and insert it into your project's index.html
entry file.
You can customize the settings by adding a workbox
section to your package.json
.
"workbox": {
importScripts: ['./worker.js'], // scripts to import into `sw.js`
globDirectory: './dist', // directory to cache (usually output dir)
globPatterns: [ // file types to include
'**/*.{css,html,js,gif,ico,jpg,png,svg,webp,woff,woff2,ttf,otf}'
}
Workbox requires at least one import script to be defined. By default, a worker.js
file, where you can write the logic for your service worker, will be read from your project's root directory and imported into sw.js
unless you change this setting. Additionally, a CDN version of Google Workbox is imported automatically.
Note: If you have this plugin active during development, you will need to either disable or manually delete the service worker to bypass caching.
Versioning
We use SemVer for versioning. For the versions available, see the tags on this repository.
License
This project is licensed under the MIT License - see the LICENSE.md file for details.