Skip to content

Commit

Permalink
feat: improve computed cacheId
Browse files Browse the repository at this point in the history
  • Loading branch information
pooya parsa committed Mar 17, 2019
1 parent 23471c4 commit cd6c9cc
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
4 changes: 2 additions & 2 deletions packages/workbox/lib/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module.exports = {
workboxURL: undefined,
importScripts: [],
autoRegister: true,
dev: false,
dev: undefined,

// Config
config: {},
Expand All @@ -16,7 +16,7 @@ module.exports = {
// Precache
preCaching: [],
cacheOptions: {
cacheId: process.env.npm_package_name || 'nuxt',
cacheId: undefined,
directoryIndex: '/',
revision: undefined
},
Expand Down
7 changes: 6 additions & 1 deletion packages/workbox/lib/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ function getOptions (moduleOptions) {
options.preCaching.unshift(options.offlinePage)
}

// Default cacheId
if (options.cacheOptions.cacheId === undefined) {
options.cacheOptions.cacheId = (process.env.npm_package_name || 'nuxt') + (this.options.dev ? '-dev' : '-prod')
}

// Normalize runtimeCaching
options.runtimeCaching = options.runtimeCaching.map(entry => ({
...entry,
Expand All @@ -83,7 +88,7 @@ function getOptions (moduleOptions) {
}

// Workbox Config
if (!options.config.debug) {
if (options.config.debug === undefined) {
// Debug field is by default set to true for localhost domain which is not always ideal
options.config.debug = options.dev || this.options.dev
}
Expand Down
2 changes: 1 addition & 1 deletion test/__snapshots__/pwa.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ workbox.precaching.precacheAndRoute([
\\"/offline.png\\",
\\"precache.js\\"
], {
\\"cacheId\\": \\"nuxt\\",
\\"cacheId\\": \\"nuxt-prod\\",
\\"directoryIndex\\": \\"/\\"
})
Expand Down

0 comments on commit cd6c9cc

Please sign in to comment.