Skip to content
Node.js script to generate simple ServiceWorker file.
Branch: master
Clone or download
bobbylej Add simple SW generator
Add script to generate SW, template for SW, README, LICENSE and
package.json.
Latest commit dd496be Jun 28, 2018
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.gitignore Add simple SW generator Jul 17, 2018
LICENSE.md Add simple SW generator Jul 17, 2018
README.md Add simple SW generator Jul 17, 2018
package.json Add simple SW generator Jul 17, 2018
sw-generator.js Add simple SW generator Jul 17, 2018
sw-template.js Add simple SW generator Jul 17, 2018

README.md

Simple SW generator

Instalation

You can install this repository as a package by running:

npm install bobbylej/simple-sw-generator
or
yarn add bobbylej/simple-sw-generator

Use

Add script inside package.json

"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

Flags

Options to generator must be specified in the command line.

--source

Path to the directory where are stored files from builded application which you want to cache in browser.

default: ./dist/

--dist

Path with filename of generated Service Worker.

default: ./dist/service-worker.js

--template

Path to template file.

default: ./gw-template.js

--cache

Name of the cache store, where you want to save all resources.

default: your-cache-name

--navigationFallback

Path to fallback file. Important when you have SPA.

default: index.html

Technologies used

Node.js (with libraries fs, minimist and glob), ES6.

I wrote script and template using ES6 as Service Workers are supported only in browsers that also support ES6.

You can’t perform that action at this time.