Simple SW generator
You can install this repository as a package by running:
npm install bobbylej/simple-sw-generator or yarn add bobbylej/simple-sw-generator
Add script inside
"sw": "node sw-generate.js"
you can also add there some flags, i.e.
"sw": "node sw-generate.js --source ./dist --dist ./dist/service-worker.js"
and run it when application is built
npm run sw or yarn sw
Options to generator must be specified in the command line.
Path to the directory where are stored files from builded application which you want to cache in browser.
Path with filename of generated Service Worker.
Path to template file.
Name of the cache store, where you want to save all resources.
Path to fallback file. Important when you have SPA.
Node.js (with libraries
I wrote script and template using ES6 as Service Workers are supported only in browsers that also support ES6.