0.0.6 • Published 5 years ago

parcel-plugin-workbox-precache v0.0.6

Weekly downloads
2
License
MIT
Repository
github
Last release
5 years ago

parcel-plugin-workbox-precache

Parcel plugin that generates a precache manifest of the bundle and injects it in the service_worker.js file.

Installation

$ npm i -d parcel-plugin-workbox-precache

or

$ yarn add --dev parcel-plugin-workbox-precache

Attention: parcel-bundler has to be installed

Usage

This module can be used to generate a precache manifest for use with workbox. It expects an asset named service_worker.js after the Parcel bundler has been run. It injects a importScripts of workbox from the Google CDN and injects a generated precache manifest as a constant named precacheManifest.

The script is injected in the head of the service worker file. Injected code is surrounded with the comments //BEGIN workbox and //END workbox, when the comments are found the code is injected between them. This is to make sure that parcel dev works as expected.

Note that this plugin probably does not work with multiple entry assets.

Example

index.html

<html>
<head>
<script src="./index.js"></script>
</head>
<body>
</body>
</html>

index.js

navigator.serviceWorker.register('/service_worker.js');

service_worker.js

/* global self, workbox, precacheManifest */
workbox.precacheAndRoute(precacheManifest);
0.0.6

5 years ago

0.0.5

5 years ago

0.0.4

5 years ago

0.0.3

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago