diff --git a/docs/modules/workbox.md b/docs/modules/workbox.md index 42434a13..f0e51845 100644 --- a/docs/modules/workbox.md +++ b/docs/modules/workbox.md @@ -145,7 +145,7 @@ Workbox takes a lot of the heavy lifting out of precaching by simplifying the AP Default is auto generated based on `publicPath`. Supports CDN too. -Default: `/_nuxt/(?!.*(__webpack_hmr|hot-update))` +Default: `/_nuxt/` ### `pagesURLPattern` @@ -153,7 +153,7 @@ Default: `/_nuxt/(?!.*(__webpack_hmr|hot-update))` Default is auto generated based on `router.base`. -Default: `/(?!.*(__webpack_hmr|hot-update))` +Default: `/` diff --git a/packages/workbox/lib/options.js b/packages/workbox/lib/options.js index 58da76d5..344323ee 100644 --- a/packages/workbox/lib/options.js +++ b/packages/workbox/lib/options.js @@ -3,8 +3,6 @@ const path = require('path') const defaults = require('./defaults') const { joinUrl, getRouteParams, startCase } = require('@nuxtjs/pwa-utils') -const HMRRegex = '(?!.*(__webpack_hmr|hot-update))' - function getOptions (moduleOptions) { const options = Object.assign({}, defaults, moduleOptions, this.options.workbox) @@ -40,7 +38,7 @@ function getOptions (moduleOptions) { // Cache all _nuxt resources at runtime if (!options.assetsURLPattern) { - options.assetsURLPattern = joinUrl(options.publicPath, HMRRegex) + options.assetsURLPattern = options.publicPath } if (options.cacheAssets) { options.runtimeCaching.push({ @@ -51,7 +49,7 @@ function getOptions (moduleOptions) { // Optionally cache other routes for offline if (!options.pagesURLPattern) { - options.pagesURLPattern = joinUrl(options.routerBase, HMRRegex) + options.pagesURLPattern = options.routerBase } if (options.offline && !options.offlinePage) { options.runtimeCaching.push({ diff --git a/test/__snapshots__/pwa.test.js.snap b/test/__snapshots__/pwa.test.js.snap index d00c4328..52054281 100644 --- a/test/__snapshots__/pwa.test.js.snap +++ b/test/__snapshots__/pwa.test.js.snap @@ -106,10 +106,10 @@ workbox.precaching.precacheAndRoute([ // Register route handlers for runtimeCaching workbox.routing.registerRoute(new RegExp('https://google.com/.*'), new workbox.strategies.CacheFirst ({}), 'GET') -workbox.routing.registerRoute(new RegExp('/_nuxt/(?!.*(__webpack_hmr|hot-update))'), new workbox.strategies.CacheFirst ({}), 'GET') +workbox.routing.registerRoute(new RegExp('/_nuxt/'), new workbox.strategies.CacheFirst ({}), 'GET') // Register router handler for offlinePage -workbox.routing.registerRoute(new RegExp('/(?!.*(__webpack_hmr|hot-update))'), ({event}) => { +workbox.routing.registerRoute(new RegExp('/'), ({event}) => { return new workbox.strategies.NetworkFirst().handle({event}) .catch(() => caches.match('/offline.html')) }) diff --git a/test/hmr.js b/test/hmr.js deleted file mode 100644 index 4ae62f5f..00000000 --- a/test/hmr.js +++ /dev/null @@ -1,73 +0,0 @@ -// This is a manual playground for HMR Regexes -const chalk = require('chalk') - -const HMRRegex = '(?!.*(__webpack_hmr|hot-update))' - -const CSNPublicPath = 'https://cdn.com' - -const regexes = { - // Regex for cacheFirst - cacheFirst: new RegExp(`/_nuxt/${HMRRegex}`), - cacheFirstCDN: new RegExp(`${CSNPublicPath}/${HMRRegex}`), - - // Regex for networkFist - networkFirst: new RegExp(`/${HMRRegex}`) -} - -const lists = { - // URLs should be matched with cacheFirst - cacheFirst: [ - '/_nuxt/foo.js', - '/_nuxt/foo/bar.json', - '/_nuxt/_bar/baz.134.png', - '/_nuxt/123.jpg?x=123' - ], - - // CDN URLs - cdn: [ - `${CSNPublicPath}/_nuxt/123.foo.js`, - `${CSNPublicPath}/bar/bar/123.js` - ], - - // URLs should be matched with networkFirst - networkFirst: [ - '/', - '/test.txt', - '/boo', - '/_foo/bar/baz', - '/foo/bar/baz/a.txt?y=123' - ], - - // Webpack HMR URLs - webpack: [ - '/__webpack_hmr', - '/__webpack_hmr/', - '/__webpack_hmr/client/chunk.json', - '/__webpack_hmr/client/chunk.123.json?a=123', - '/hot-update.json', - '/abc123def.hot-update.json', - '/_nuxt/hot-update.json', - '/_nuxt/abc123edf.hot-update.json', - '/_nuxt/foo/hot-hot-update.json', - '/_nuxt/foo/abc123def.hot-hot-update.json' - ] -} - -const log = (msg, ok) => { - console.log(chalk[ok ? 'green' : 'red'](`${ok ? '✓' : '✕'} ${msg}`)) -} - -const allShouldMatch = (regexName, listName) => lists[listName].forEach(item => { - log(`${regexName} should match ${item}`, regexes[regexName].test(item)) -}) - -const allShouldNotMatch = (regexName, listName) => lists[listName].forEach(item => { - log(`${regexName} should not match ${item}`, !regexes[regexName].test(item)) -}) - -allShouldMatch('cacheFirst', 'cacheFirst') -allShouldMatch('cacheFirstCDN', 'cdn') -allShouldNotMatch('cacheFirst', 'webpack') - -allShouldMatch('networkFirst', 'networkFirst') -allShouldNotMatch('networkFirst', 'webpack')