Skip to content

service worker register by manifest[webpack-manifest-resource-plugin]

Notifications You must be signed in to change notification settings

hubcarl/service-worker-register

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

service-worker-register

NPM version build status Test coverage David deps npm download

service worker register by webpack service worker manifest service-worker-precache-webpack-plugin

Install

npm i service-worker-register --save

Usage

const serviceWorkerRegister = require('service-worker-register');
// The service-worker.js name will get really url address by sw-mapping.json file
serviceWorkerRegister.register('service-worker.js');

Configuration

serviceWorkerRegister.register(filename, options):

  • options.scope: {String} default: / - service worker scope
  • options.manifestUrl: {String} default: /public/sw-mapping.json - service worker filename mapping file
  • options.report: {Function} optional - service worker register error report interface

Function

The plugin depend on service-worker-precache-webpack-plugin

  • webpack-manifest-resource-plugin inject sw-mapping.json file content to global var SERVICE_WORKER_MANIFEST
// sw-manifest.js
{
  "config": {
    "localPublicPath": "/public/",
    "publicPath": "/public/"
  },
  "service-worker.js": "service-worker.4434ddf3js"
}
  • if SERVICE_WORKER_MANIFEST is be inject, use this configuration directly, otherwise launch the network based on options.manifestUrl URL

License

MIT