service-worker

About service worker.

usage:

  1. place ./src/sw.js in your project src dir
# refrer this code:
https://github.com/afeiship/configuration-files/blob/master/service-worker/sw.js
  1. Add this code to you app.js
import runtime from 'serviceworker-webpack-plugin/lib/runtime';

// ...
  componentDidMount() {
    //...
    this.registerSw();
  }

  registerSw() {
    if ('serviceWorker' in navigator) {
      runtime.register();
    }
  }
// ...
  1. use app-kits
plugins:[
  //...
  plugins.serviceWorker()
]

resources:

  • https://github.com/oliviertassinari/serviceworker-webpack-plugin