GoogleChromeLabs / sw-precache

[Deprecated] A node module to generate service worker code that will precache specific resources so they work offline.
https://developers.google.com/web/tools/workbox/guides/migrations/migrate-from-sw
Apache License 2.0
5.22k stars 388 forks source link

Customising service worker's filename #335

Open saleemepoch opened 7 years ago

saleemepoch commented 7 years ago

The documentation doesn't mention a way to change the name of the generated file.

It does mention gulp, but I am using Angular 4's angular-cli to generate my assets and then run sw-precache separately to generate the service worker.

the packages.json file consists of this command: "sw": "sw-precache --config=sw-precache-config.js --verbose"

And the sw-precache-config.js file has the following options configured:

module.exports = { navigateFallback: '/index.html', root: '../public', staticFileGlobs: [ '../public/index.html', '../public/.js', '../public/.css', '../public/.woff2', '../public/.svg', '../public/**.ttf' ] };

I want to be able to generate custom-named service worker file each time I run npm run sw.

How can I do this?

kamleshchandnani commented 7 years ago

Add this property to the config object "swFile": "public/build/custom-service-worker.js"

saleemepoch commented 7 years ago

Thanks, that worked.

This should be added to the documentation.

michaelaflores commented 6 years ago

@jeffposnick would you be open to an MR adding the documentation for this?