Skip to content

Commit

Permalink
v0.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mischnic committed Jun 8, 2019
1 parent 0769df7 commit 065ddec
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 79 deletions.
76 changes: 0 additions & 76 deletions README.md

This file was deleted.

1 change: 1 addition & 0 deletions README.md
76 changes: 76 additions & 0 deletions parcel-plugin-sw-cache/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# Parcel plugin for sw-caching

A [Parcel](https://parceljs.org/) plugin to run [workbox-build](https://github.com/GoogleChrome/workbox) after every build.

```sh
yarn add -D parcel-plugin-sw-cache
# or
npm install -D parcel-plugin-sw-cache
```

The plugin is configured using the `cache` object inside `package.json` of your project. ([Example](example/package.json)).
Configuration keys used by the plugin (default options first):
```js
{
"dependencies": {
// ...
},
//...
"cache": {
"disablePlugin": false || true,
"inDev": false || true,
"strategy": "default" || "inject"
"clearDist": true || false
}
//...
}
```

The remaining properties in this object will be passed to `generateSW` or `injectManifest` (depending on `strategy`). See https://developers.google.com/web/tools/workbox/reference-docs/latest/module-workbox-build

In `inject` mode, occurences of `__PUBLIC` will be replaced with Parcel's public-url option. In this case, `swSrc` is also a required parameter.

No configuration options are mandatory, the default configuration will work just fine. (Creating a service worker to precache all files in the output directory without runtime caching). With `strategy: "default"`, the default parameters passed to workbox-build are (which precaching all html, js, css, jpg and png files):
```js
{
globDirectory: outDir,
globPatterns: ["**/*.{html,js,css,jpg,png}"],
swDest: swDest,
navigateFallback: publicURL + "/index.html",
clientsClaim: true,
skipWaiting: true,
templatedURLs: {
"/": ["index.html"]
}
}
```
and with `inject`:
```js
{
globDirectory: outDir,
globPatterns: [
"**/*.{html,js,css,jpg,png,gif,svg,eot,ttf,woff,woff2}"
],
swDest: swDest,
templatedURLs: {
"/": ["index.html"]
}
}
```

To specify a RegExp, use an array instead (`ignoreURLParametersMatching`, `navigateFallbackWhitelist`, `runtimeCaching.urlPattern`, `injectionPointRegexp`).
```js
runtimeCaching: [
{
urlPattern: /my-match\/api\.[0-9]+/i
}
]
```
becomes
```json
"runtimeCaching": [
{
"urlPattern": ["my-match\/api\\.[0-9]+", "i"]
}
]
```
6 changes: 3 additions & 3 deletions parcel-plugin-sw-cache/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "parcel-plugin-sw-cache",
"version": "0.2.7",
"version": "0.3.0",
"description": "A parcel plugin for workbox serviceworker (pre)caching",
"main": "index.js",
"repository": "https://github.com/mischnic/parcel-plugin-sw-cache",
Expand All @@ -11,14 +11,14 @@
"license": "MIT",
"dependencies": {
"replace-in-file": "^4.1.0",
"rimraf": "^2.6.3",
"workbox-build": "^4.3.1"
},
"peerDependencies": {
"parcel-bundler": "^1.11.0"
},
"devDependencies": {
"parcel-bundler": "^1.12.3",
"rimraf": "^2.6.3"
"parcel-bundler": "^1.12.3"
},
"files": []
}

0 comments on commit 065ddec

Please sign in to comment.