forked from vite-pwa/vite-plugin-pwa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
types.ts
235 lines (230 loc) · 5.51 KB
/
types.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
/* eslint-disable no-use-before-define */
import type { GenerateSWOptions, InjectManifestOptions, ManifestEntry } from 'workbox-build'
import type { OutputBundle } from 'rollup'
/**
* Plugin options.
*/
export interface VitePWAOptions {
/**
* Build mode
*
* @default process.env.NODE_ENV or "production"
*/
mode?: 'development' | 'production'
/**
* @default 'public'
*/
srcDir?: string
/**
* @default 'dist'
*/
outDir?: string
/**
* @default 'sw.js'
*/
filename?: string
/**
* @default 'generateSW'
*/
strategies?: 'generateSW' | 'injectManifest'
/**
* The scope to register the Service Worker
*
* @default same as `base` of Vite's config
*/
scope?: string
/**
* Inject the service worker register inlined in the index.html
*
* With `auto` set, depends on whether you used the `import { registerSW } from 'virtual:pwa-register'`
* it will do nothing or use the `script` mode
*
* `inline` - inject a simple register, inlined with the generated html
*
* `script` - inject <script/> in <head>, with the `sr` to a generated simple register
*
* `null` - do nothing, you will need to register the sw you self, or imports from `virtual:pwa-register`
*
* @default 'auto'
*/
injectRegister: 'inline' | 'script' | 'auto' | null | false
/**
* Mode for the virtual register.
* Does NOT available for `injectRegister` set to `inline` or `script`
*
* `prompt` - you will need to show a popup/dialog to the user to confirm the reload.
*
* `autoUpdate` - when new content is available, the new service worker will update caches and reload all browser
* windows/tabs with the application open automatically, it must take the control for the application to work
* properly.
*
* @default 'prompt'
*/
registerType?: 'prompt' | 'autoUpdate'
/**
* Minify the generated manifest
*
* @default true
*/
minify: boolean
/**
* The manifest object
*/
manifest: Partial<ManifestOptions> | false
/**
* Whether to add the `crossorigin="use-credentials"` attribute to `<link rel="manifest">`
* @default false
*/
useCredentials?: boolean
/**
* The workbox object for `generateSW`
*/
workbox: Partial<GenerateSWOptions>
/**
* The workbox object for `injectManifest`
*/
injectManifest: Partial<InjectManifestOptions>
/**
* Override Vite's base options only for PWA
*
* @default "base" options from Vite
*/
base?: string
/**
* `public` resources to be added to the PWA manifest.
*
* You don't need to add `manifest` icons here, it will be auto included.
*
* The `public` directory will be resolved from Vite's `publicDir` option directory.
*/
includeAssets: string | string[] | undefined
/**
* By default the icons listed on `manifest` option will be included
* on the service worker *precache* if present under Vite's `publicDir`
* option directory.
*/
includeManifestIcons: true
}
export interface ResolvedVitePWAOptions extends Required<VitePWAOptions> {
swSrc: string
swDest: string
workbox: GenerateSWOptions
injectManifest: InjectManifestOptions
}
export interface ManifestOptions {
/**
* @default _npm_package_name_
*/
name: string
/**
* @default _npm_package_name_
*/
short_name: string
/**
* @default _npm_package_description_
*/
description: string
/**
*
*/
icons: Record<string, any>[]
/**
* @default `routerBase + '?standalone=true'`
*/
start_url: string
/**
* Restricts what web pages can be viewed while the manifest is applied
*/
scope: string
/**
* A string that represents the identity for the application
*/
id: string
/**
* Defines the default orientation for all the website's top-level
*/
orientation: 'any' | 'natural' | 'landscape' | 'landscape-primary' | 'landscape-secondary' | 'portrait' | 'portrait-primary' | 'portrait-secondary'
/**
* @default `standalone`
*/
display: string
/**
* @default `#ffffff`
*/
background_color: string
/**
* @default '#42b883
*/
theme_color: string
/**
* @default `ltr`
*/
dir: 'ltr' | 'rtl'
/**
* @default `en`
*/
lang: string
/**
* @default A combination of `routerBase` and `options.build.publicPath`
*/
publicPath: string
/**
* @default []
*/
related_applications: {
platform: string
url: string
id?: string
}[]
/**
* @default false
*/
prefer_related_applications: boolean
/**
* @default []
*/
protocol_handlers: {
protocol: string
url: string
}[]
/**
* @default []
*/
shortcuts: {
name: string
short_name?: string
url: string
description?: string
icons: string[]
}[]
/**
* @default []
*/
screenshots: {
src: string
sizes: string
label?: string
platform?: 'narrow' | 'wide' | 'android' | 'ios' | 'kaios' | 'macos' | 'windows' | 'windows10x' | 'chrome_web_store' | 'play' | 'itunes' | 'microsoft-inbox' | 'microsoft-store' | string
type?: string
}[]
/**
* @default []
*/
categories: string[]
/**
* @default ''
*/
iarc_rating_id: string
}
export interface VitePluginPWAAPI {
extendManifestEntries(fn: ExtendManifestEntriesHook): void
/*
* Explicitly generate the manifests.
*/
generateBundle(bundle?: OutputBundle): OutputBundle
/*
* Explicitly generate the PWA services worker.
*/
generateSW(): Promise<void>
}
export type ExtendManifestEntriesHook = (manifestEntries: (string | ManifestEntry)[]) => (string | ManifestEntry)[] | undefined