UNPKG

8.66 kBTypeScriptView Raw
1import { HTTPMethod } from 'workbox-routing';
2import { Plugin } from 'workbox-background-sync';
3import { Plugin as Plugin$1 } from 'workbox-broadcast-update';
4import { Plugin as Plugin$2 } from 'workbox-cacheable-response';
5import { Plugin as Plugin$3 } from 'workbox-expiration';
6import { Plugin as Plugin$4 } from 'workbox-range-requests';
7import { StaleWhileRevalidateOptions, CacheFirstOptions, NetworkFirstOptions, NetworkOnlyOptions, CacheOnlyOptions } from 'workbox-strategies';
8
9/* eslint camelcase: 0 */
10
11interface ManifestOptions {
12 /**
13 * Default: _npm_package_name_
14 */
15 name: string,
16 /**
17 * Default: _npm_package_name_
18 */
19 short_name: string,
20 /**
21 * Default: _npm_package_description_
22 */
23 description: string,
24 /**
25 *
26 */
27 icons: Record<string, any>[],
28 /**
29 * Default: `routerBase + '?standalone=true'`
30 */
31 start_url: string,
32 /**
33 * Default: `standalone`
34 */
35 display: string,
36 /**
37 * Default: `#ffffff`
38 */
39 background_color: string,
40 /**
41 * Default: undefined
42 */
43 theme_color: string,
44 /**
45 * Default: `ltr`
46 */
47 dir: 'ltr' | 'rtl',
48 /**
49 * Default: `en`
50 */
51 lang: string,
52 /**
53 * Default: `false`
54 */
55 useWebmanifestExtension: boolean,
56 /**
57 * Default: A combination of `routerBase` and `options.build.publicPath`
58 */
59 publicPath: string,
60
61 fileName: string,
62 crossorigin: boolean
63}
64
65/* eslint camelcase: 0 */
66
67
68type OgImageObject = {
69 path?: string,
70 width?: number,
71 height?: number,
72 type?: string
73}
74
75interface MetaOptions extends Partial<ManifestOptions> {
76 /**
77 * Default: `utf-8`
78 */
79 charset: string,
80 /**
81 * Default: `width=device-width, initial-scale=1`
82 *
83 * Meta: `viewport`
84 */
85 viewport: string,
86 /**
87 * Default: `true`
88 *
89 * Meta: `mobile-web-app-capable`
90 */
91 mobileApp: boolean,
92 /**
93 * Default: `false`
94 *
95 * Meta: `apple-mobile-web-app-capable`
96 */
97 mobileAppIOS: boolean,
98 /**
99 * Default: `default`
100 */
101 appleStatusBarStyle: string,
102 /**
103 * Default: `true` (to use options.icons)
104 *
105 * Meta: `shortcut icon` + `apple-touch-icon`
106 */
107 favicon: boolean,
108 /**
109 * Default: _npm_package_name_
110 *
111 * Meta: `title`
112 */
113 name: string,
114 /**
115 * @deprecated use meta.name
116 */
117 title?: string,
118 /**
119 * Default: _npm_package_author_name_
120 *
121 * Meta: `author`
122 */
123 author: string,
124 /**
125 * Default: _npm_package_description_
126 *
127 * Meta: `description`
128 */
129 description: string,
130 /**
131 * Default: `options.loading.color`
132 *
133 * Meta: `description`
134 */
135 theme_color: string,
136 /**
137 * Default: `en`
138 *
139 * Meta: `lang`
140 */
141 lang: string,
142 /**
143 * Default: `website`
144 *
145 * Meta: `og:type`
146 */
147 ogType: string,
148 /**
149 * Default: _npm_package_name_
150 *
151 * Meta: `og:site_name`
152 */
153 ogSiteName: string | true,
154 /**
155 * Default: _npm_package_name_
156 *
157 * Meta: `og:title`
158 */
159 ogTitle: string | true,
160 /**
161 * Default: _npm_package_description_
162 *
163 * Meta: `og:description`
164 */
165 ogDescription: string | true,
166 /**
167 * Default: `undefined`
168 *
169 * Meta: `N/A`
170 */
171 ogHost: string | undefined,
172 /**
173 * Default: `true`
174 *
175 * Meta: `og:image` and sub-tags
176 */
177 ogImage: boolean | string | OgImageObject,
178 /**
179 * Default: ogHost (if defined)
180 *
181 * Meta: `og:url`
182 */
183 ogUrl: string | undefined | true,
184 /**
185 * Default: `undefined`
186 *
187 * Meta: `twitter:card`
188 */
189 twitterCard: string | undefined,
190 /**
191 * Default: `undefined`
192 *
193 * Meta: `twitter:site`
194 */
195 twitterSite: string | undefined,
196 /**
197 * Default: `undefined`
198 *
199 * Meta: `twitter:creator`
200 */
201 twitterCreator: string | undefined,
202 /**
203 * Default: `false`
204 */
205 nativeUI: boolean
206}
207
208type iOSType = 'ipad' | 'ipadpro9' | 'ipadpro9' | 'ipadpro10' | 'ipadpro12' | 'iphonese' | 'iphone6' | 'iphoneplus' | 'iphonex' | 'iphonexr' | 'iphonexsmax'
209type iOSSize = [number, number, iOSType]
210
211interface IconOptions {
212 /**
213 * Default: `[srcDir]/[staticDir]/icon.png`
214 */
215 source: string,
216 /**
217 * Default: `icon.png`
218 */
219 fileName: string,
220 /**
221 * Array of sizes to be generated (Square).
222 * Default: `[64, 120, 144, 152, 192, 384, 512]`
223 */
224 sizes: number[],
225
226 /**
227 * Default:
228 * ```javascript
229 * [
230 * [1536, 2048, 'ipad'], // Ipad
231 * [1536, 2048, 'ipadpro9'], // Ipad Pro 9.7"
232 * [1668, 2224, 'ipadpro10'], // Ipad Pro 10.5"
233 * [2048, 2732, 'ipadpro12'], // Ipad Pro 12.9"
234 * [640, 1136, 'iphonese'], // Iphone SE
235 * [50, 1334, 'iphone6'], // Iphone 6
236 * [1080, 1920, 'iphoneplus'], // Iphone Plus
237 * [1125, 2436, 'iphonex'], // Iphone X
238 * [828, 1792, 'iphonexr'], // Iphone XR
239 * [1242, 2688, 'iphonexsmax'] // Iphone XS Max
240 * ]
241 * ```
242 */
243 iosSizes: iOSSize[],
244 /**
245 * Default: `icons`
246 */
247 targetDir: string,
248 /**
249 * Make icons accessible through `ctx` or Vue instances.
250 *
251 * Default: `true`
252 */
253 plugin: boolean,
254 /**
255 * Name of property for accessible icons.
256 *
257 * Default: `$icon`
258 */
259 pluginName: string,
260 /**
261 * Array or string of icon purpose.
262 *
263 * Default: `['any', 'maskable']`
264 */
265 purpose: string[] | string,
266 /**
267 * Cache dir for generated icons
268 *
269 * Default: `{rootDir}/node_modules/.cache/icon`
270 */
271 cacheDir: string,
272
273 publicPath: string
274}
275
276type CachingStrategy = 'CacheFirst' | 'CacheOnly' | 'NetworkFirst' | 'NetworkOnly' | 'StaleWhileRevalidate'
277
278type StrategyOptions =
279 Omit<StaleWhileRevalidateOptions | CacheFirstOptions | NetworkFirstOptions | NetworkOnlyOptions | CacheOnlyOptions, 'plugins'>
280
281type StrategyPluginOf<name, T> = {
282 use: name
283 config: ConstructorParameters<T>[0] | ConstructorParameters<T>
284}
285
286type BackgroundSync = StrategyPluginOf<'BackgroundSync', Plugin>
287type BroadcastUpdate = StrategyPluginOf<'BroadcastUpdate', Plugin$1>
288type CacheableResponse = StrategyPluginOf<'CacheableResponse', Plugin$2>
289type Expiration = StrategyPluginOf<'Expiration', Plugin$3>
290type RangeRequests = StrategyPluginOf<'RangeRequests', Plugin$4>
291
292type StrategyPlugin = BackgroundSync | BroadcastUpdate | CacheableResponse | Expiration | RangeRequests
293
294interface RuntimeCaching {
295 urlPattern: string
296 handler?: CachingStrategy
297 method?: HTTPMethod
298 strategyOptions?: StrategyOptions
299 strategyPlugins?: StrategyPlugin[]
300}
301
302interface WorkboxOptions {
303 dev: boolean,
304 workboxVersion: string,
305 workboxURL: string,
306 importScripts: string[],
307 /**
308 * Default: `true`
309 */
310 autoRegister: boolean,
311 /**
312 * Default: `true` for production mode
313 */
314 enabled: boolean,
315 cacheNames: Record<string, any>,
316 config: Record<string, any>,
317 /**
318 * Default: `true`
319 */
320 clientsClaim: boolean,
321 /**
322 * Default: `true`
323 */
324 skipWaiting: boolean,
325 /**
326 * Default: `false`
327 */
328 offlineAnalytics: boolean,
329 workboxExtensions: string | string[],
330 /**
331 * Default: `[]`
332 */
333 preCaching: string[] | {url: string, revision: string}[],
334 cacheOptions: {
335 /**
336 * Default: `<npm package name> || nuxt`
337 */
338 cacheId: string,
339 /**
340 * Default: `/`
341 */
342 directoryIndex: string,
343 /**
344 * Default: `undefined`
345 */
346 revision: string | undefined
347 },
348 cachingExtensions: string | string[],
349 cleanupOutdatedCaches: boolean,
350 /**
351 * Default: `true`
352 */
353 offline: boolean,
354 /**
355 * Default: `NetworkFirst`
356 */
357 offlineStrategy: CachingStrategy,
358 offlinePage: string,
359 offlineAssets: string[],
360 runtimeCaching: RuntimeCaching[],
361 /**
362 * Default: `true`
363 */
364 cacheAssets: boolean,
365 routingExtensions: string | string[],
366 /**
367 * Default: `/_nuxt/`
368 */
369 assetsURLPattern: string,
370 /**
371 * Auto generated based on `router.base`
372 *
373 * Default: `/`
374 */
375 pagesURLPattern: string,
376 swTemplate: string,
377 swURL: string,
378 swDest: string,
379 /**
380 * Default: `routerBase`
381 */
382 swScope: string,
383 /**
384 * Default: `/`
385 */
386 routerBase: string,
387 /**
388 * Default: `/_nuxt`
389 */
390 publicPath: string
391}
392
393interface PWAOptions {
394 meta?: Partial<MetaOptions> | false;
395 icon?: Partial<IconOptions> | false;
396 workbox?: Partial<WorkboxOptions> | false;
397 manifest?: Partial<ManifestOptions> | false;
398}
399declare function pwa(moduleOptions: PWAOptions): Promise<void>;
400declare namespace pwa {
401 var meta: {
402 name: string;
403 version: string;
404 };
405}
406
407declare module '@nuxt/types/config/index' {
408 interface NuxtOptions {
409 pwa?: Partial<PWAOptions>;
410 meta?: Partial<MetaOptions> | false;
411 icon?: Partial<IconOptions> | false;
412 workbox?: Partial<WorkboxOptions> | false;
413 manifest?: Partial<ManifestOptions> | false;
414 }
415}
416
417export default pwa;