A plugin for Gitbook that generates a service worker By using Workbox
npm install gitbook-plugin-workboxThis plugin uses Workbox - a module written by Google - to automatically generate a service worker and
include it in your gitbook output.
Add this to your gitbook by including it in your book.json file.
```
{
"plugins": ["workbox"]
}
Be sure to run gitbook install before building your book, or as part of your automated build process.
in the root directory (Maybe there is a package.json in the root directory)Like the following.
`workbox-config.js
module.exports = {
cacheId: "hoge",
globPatterns: [
"*/.{html,js,css}"
],
clientsClaim: true,
runtimeCaching: [
{
urlPattern: /\.(jpg|png|svg|gif|woff|ttf|eot)/,
handler: "cacheFirst",
options: {
cacheName: "assets",
expiration: {
maxAgeSeconds: 60 60 24 * 14
}
}
},
],
};`$3
This plugin already set globDirectory and swDest.
(Confirm index.js)
`
{
globDirectory: "_book",
swDest: "_book/service-worker.js",
}
``