create-sw
A tool to generate robust Service Worker for your application. Refactored and improved from sw-precache
Install
npm i -S create-sw
or you can install it globally:
npm i -g create-sw
Usage
1、build service-worker.js
This tool provides a cli tool to help you build your own service-worker.js
create-sw --config=sw-config.js
sw-config.js
has the same options in sw-precache and some unique options:
externals [Array]
An array contains the external resources url that you want to precache.
// sw-config.jsmoduleexports = // ... externals: 'https://cdn.bootcss.com/jquery/3.2.1/jquery.js' 'https://cdn.bootcss.com/bootstrap/4.0.0-beta/css/bootstrap.css' ;
minify [Boolean]
An option to deside if the output sw.js is minified. Defaults to false
// sw-config.jsmoduleexports = // ... minify: true;
2、runtime
This tool also provides a runtime for you to install Service Worker and set a callback to the Service Worker lifecycle:
// In your Javascript codevar runtime = ;runtime