|
1 | 1 | import { resolve } from 'path' |
2 | 2 | import { joinUrl, getRouteParams, startCase, randomString, PKG_DIR } from '../utils' |
3 | | -import type { WorkboxOptions } from '../../types/workbox' |
| 3 | +import type { WorkboxOptions, PWAContext } from '../../types' |
4 | 4 | import { defaults } from './defaults' |
5 | 5 |
|
6 | | -export function getOptions (nuxt, pwa): WorkboxOptions { |
| 6 | +export function getOptions (nuxt, pwa: PWAContext): WorkboxOptions { |
7 | 7 | const options: WorkboxOptions = { ...defaults, ...pwa.workbox } |
8 | 8 |
|
9 | 9 | // enabled |
@@ -62,28 +62,28 @@ export function getOptions (nuxt, pwa): WorkboxOptions { |
62 | 62 | }) |
63 | 63 | } |
64 | 64 |
|
65 | | - // Add start_url to precaching |
66 | | - if (pwa.manifest && pwa.manifest.start_url) { |
67 | | - options.preCaching.unshift(pwa.manifest.start_url) |
68 | | - } |
69 | | - |
70 | 65 | // Default revision |
71 | 66 | if (!options.cacheOptions.revision) { |
72 | 67 | options.cacheOptions.revision = randomString(12) |
73 | 68 | } |
74 | | - const normalizePreCaching = (arr: any[]) => arr.map(url => ({ |
| 69 | + const normalizePreCaching = (arr: any | any[]) => [].concat(arr).map(url => ({ |
75 | 70 | revision: options.cacheOptions.revision, |
76 | 71 | ...(typeof url === 'string' ? { url } : url) |
77 | 72 | })) |
78 | 73 |
|
| 74 | + // Add start_url to precaching |
| 75 | + if (pwa.manifest && pwa.manifest.start_url) { |
| 76 | + options.preCaching.unshift(...normalizePreCaching(pwa.manifest.start_url)) |
| 77 | + } |
| 78 | + |
79 | 79 | // Add offlineAssets to precaching |
80 | 80 | if (options.offlineAssets.length) { |
81 | 81 | options.preCaching.unshift(...normalizePreCaching(options.offlineAssets)) |
82 | 82 | } |
83 | 83 |
|
84 | 84 | // Add offlinePage to precaching |
85 | 85 | if (options.offlinePage) { |
86 | | - options.preCaching.unshift(...(normalizePreCaching([options.offlinePage]))) |
| 86 | + options.preCaching.unshift(...(normalizePreCaching(options.offlinePage))) |
87 | 87 | } |
88 | 88 |
|
89 | 89 | // Default cacheId |
|
0 commit comments