Skip to content

Commit cd6c9cc

Browse files
author
pooya parsa
committed
feat: improve computed cacheId
1 parent 23471c4 commit cd6c9cc

3 files changed

Lines changed: 9 additions & 4 deletions

File tree

packages/workbox/lib/defaults.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ module.exports = {
44
workboxURL: undefined,
55
importScripts: [],
66
autoRegister: true,
7-
dev: false,
7+
dev: undefined,
88

99
// Config
1010
config: {},
@@ -16,7 +16,7 @@ module.exports = {
1616
// Precache
1717
preCaching: [],
1818
cacheOptions: {
19-
cacheId: process.env.npm_package_name || 'nuxt',
19+
cacheId: undefined,
2020
directoryIndex: '/',
2121
revision: undefined
2222
},

packages/workbox/lib/options.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@ function getOptions (moduleOptions) {
7070
options.preCaching.unshift(options.offlinePage)
7171
}
7272

73+
// Default cacheId
74+
if (options.cacheOptions.cacheId === undefined) {
75+
options.cacheOptions.cacheId = (process.env.npm_package_name || 'nuxt') + (this.options.dev ? '-dev' : '-prod')
76+
}
77+
7378
// Normalize runtimeCaching
7479
options.runtimeCaching = options.runtimeCaching.map(entry => ({
7580
...entry,
@@ -83,7 +88,7 @@ function getOptions (moduleOptions) {
8388
}
8489

8590
// Workbox Config
86-
if (!options.config.debug) {
91+
if (options.config.debug === undefined) {
8792
// Debug field is by default set to true for localhost domain which is not always ideal
8893
options.config.debug = options.dev || this.options.dev
8994
}

test/__snapshots__/pwa.test.js.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ workbox.precaching.precacheAndRoute([
9696
\\"/offline.png\\",
9797
\\"precache.js\\"
9898
], {
99-
\\"cacheId\\": \\"nuxt\\",
99+
\\"cacheId\\": \\"nuxt-prod\\",
100100
\\"directoryIndex\\": \\"/\\"
101101
})
102102

0 commit comments

Comments
 (0)