Skip to content

Commit 2d7ed53

Browse files
jezhodgespi0
authored andcommitted
feat(workbox): allow cache names to be configured (#154)
1 parent 45ac27d commit 2d7ed53

4 files changed

Lines changed: 19 additions & 0 deletions

File tree

docs/modules/workbox.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ It is recommanded to test workbox using `nuxt build`/`nuxt start`. You can enabl
4848

4949
<!-- Config -->
5050

51+
### `cacheNames`
52+
53+
(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.
54+
5155
### `config`
5256

5357
(Object) Options to be passed to workbox before using it's modules. By default `debug` field will be set to `false` for production builds.

packages/workbox/templates/sw.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ importScripts(<%= [options.workboxURL, ...options.importScripts].map((i) => `'${
99
workbox.setConfig(<%= JSON.stringify(options.config, null, 2) %>)
1010
<% } %>
1111

12+
<% if (options.cacheNames) {%>
13+
// Set workbox cache names
14+
workbox.core.setCacheNameDetails(<%= JSON.stringify(options.cacheNames, null, 2) %>)
15+
<% } %>
16+
1217
<% if (options.clientsClaim) { %>
1318
// Start controlling any existing clients as soon as it activates
1419
workbox.core.clientsClaim()

test/__snapshots__/pwa.test.js.snap

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@ workbox.setConfig({
6464
\\"debug\\": true
6565
})
6666
67+
// Set workbox cache names
68+
workbox.core.setCacheNameDetails({
69+
\\"prefix\\": \\"test\\",
70+
\\"googleAnalytics\\": \\"test-ga\\"
71+
})
72+
6773
// Start controlling any existing clients as soon as it activates
6874
workbox.core.clientsClaim()
6975

test/fixture/nuxt.config.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ module.exports = {
3030
config: {
3131
debug: true
3232
},
33+
cacheNames: {
34+
prefix: 'test',
35+
googleAnalytics: 'test-ga'
36+
},
3337
importScripts: [
3438
'custom-sw.js'
3539
],

0 commit comments

Comments
 (0)