项目作者: Voxylu

项目描述 :
Similar to gatsby-plugin-offline but you can customize the service worker (e.g. add notifications).
高级语言: JavaScript
项目地址: git://github.com/Voxylu/gatsby-plugin-sw.git
创建时间: 2018-09-08T10:01:23Z
项目社区:https://github.com/Voxylu/gatsby-plugin-sw

开源协议:MIT License

下载


gatsby-plugin-sw

Tested only on linux with gatsby v2

Add support for making a Gatsby site work offline and more resistant to
bad network connections. It creates a service worker using workboxBuild.injectManifest.

If you’re using this plugin with gatsby-plugin-manifest (recommended) this
plugin should be listed after that plugin so the manifest file can be included
in the service worker.

Install

npm install --save gatsby-plugin-sw

How to use

  1. // In your gatsby-config.js
  2. plugins: [
  3. {
  4. resolve: 'gatsby-plugin-sw',
  5. options: {
  6. swPath: 'src/utils/my-service-worker.js', // Default to 'src/sw.js'
  7. },
  8. },
  9. ]
  1. // In your service worker e.g. src/sw.js
  2. // Required stuff
  3. importScripts(
  4. 'https://storage.googleapis.com/workbox-cdn/releases/3.4.1/workbox-sw.js'
  5. )
  6. // The plugin will pass the files to cache here
  7. workbox.precaching.precacheAndRoute([])
  8. // Another things
  9. self.addEventListener('push', () => {
  10. // ...
  11. })

Options

For now the only option avaible is swPath and it’s the location of your service worker file.