Skip to content

Commit

Permalink
feat(workbox): allow cache names to be configured (#154)
Browse files Browse the repository at this point in the history
  • Loading branch information
jezhodges authored and pi0 committed Mar 2, 2019
1 parent 45ac27d commit 2d7ed53
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 0 deletions.
4 changes: 4 additions & 0 deletions docs/modules/workbox.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ It is recommanded to test workbox using `nuxt build`/`nuxt start`. You can enabl

<!-- Config -->

### `cacheNames`

(Object) Configure the workbox cache names. See [workbox docs](https://developers.google.com/web/tools/workbox/guides/configure-workbox#configure_cache_names) for more information on this.

### `config`

(Object) Options to be passed to workbox before using it's modules. By default `debug` field will be set to `false` for production builds.
Expand Down
5 changes: 5 additions & 0 deletions packages/workbox/templates/sw.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ importScripts(<%= [options.workboxURL, ...options.importScripts].map((i) => `'${
workbox.setConfig(<%= JSON.stringify(options.config, null, 2) %>)
<% } %>

<% if (options.cacheNames) {%>
// Set workbox cache names
workbox.core.setCacheNameDetails(<%= JSON.stringify(options.cacheNames, null, 2) %>)
<% } %>

<% if (options.clientsClaim) { %>
// Start controlling any existing clients as soon as it activates
workbox.core.clientsClaim()
Expand Down
6 changes: 6 additions & 0 deletions test/__snapshots__/pwa.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ workbox.setConfig({
\\"debug\\": true
})
// Set workbox cache names
workbox.core.setCacheNameDetails({
\\"prefix\\": \\"test\\",
\\"googleAnalytics\\": \\"test-ga\\"
})
// Start controlling any existing clients as soon as it activates
workbox.core.clientsClaim()
Expand Down
4 changes: 4 additions & 0 deletions test/fixture/nuxt.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ module.exports = {
config: {
debug: true
},
cacheNames: {
prefix: 'test',
googleAnalytics: 'test-ga'
},
importScripts: [
'custom-sw.js'
],
Expand Down

0 comments on commit 2d7ed53

Please sign in to comment.