@unplugin-pwa/core 0.0.0 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +103 -2
- package/client.d.ts +6 -0
- package/dist/additional-manifest-entries.d.mts +10 -0
- package/dist/additional-manifest-entries.mjs +60 -0
- package/dist/build-pwa-asset.d.mts +18 -0
- package/dist/build-pwa-asset.mjs +87 -0
- package/dist/config.d.mts +75 -0
- package/dist/config.mjs +293 -0
- package/dist/constants.d.mts +31 -0
- package/dist/constants.mjs +41 -0
- package/dist/context-types.d.mts +155 -0
- package/dist/context.d.mts +15 -0
- package/dist/context.mjs +58 -0
- package/dist/create-generate-register-sw-script.d.mts +15 -0
- package/dist/create-generate-register-sw-script.mjs +27 -0
- package/dist/create-web-manifest-html-link.d.mts +13 -0
- package/dist/create-web-manifest-html-link.mjs +21 -0
- package/dist/dev/prepare-sw-names-and-glob-directory.d.mts +18 -0
- package/dist/dev/prepare-sw-names-and-glob-directory.mjs +75 -0
- package/dist/dev/prepare-temp-folder.d.mts +9 -0
- package/dist/dev/prepare-temp-folder.mjs +44 -0
- package/dist/dual-sw-utilities.d.mts +9 -0
- package/dist/dual-sw-utilities.mjs +16 -0
- package/dist/generate-register-sw.d.mts +14 -0
- package/dist/generate-register-sw.mjs +22 -0
- package/dist/generate-web-manifest.d.mts +9 -0
- package/dist/generate-web-manifest.mjs +12 -0
- package/dist/helpers.d.mts +33 -0
- package/dist/helpers.mjs +132 -0
- package/dist/html.d.mts +8 -0
- package/dist/html.mjs +28 -0
- package/dist/index.d.mts +9 -0
- package/dist/inject-generate-register-sw.d.mts +16 -0
- package/dist/inject-generate-register-sw.mjs +22 -0
- package/dist/inject-web-manifest-html-link.d.mts +14 -0
- package/dist/inject-web-manifest-html-link.mjs +20 -0
- package/dist/inspector-utils.d.mts +26 -0
- package/dist/inspector-utils.mjs +47 -0
- package/dist/logs.d.mts +8 -0
- package/dist/logs.mjs +19 -0
- package/dist/package-DpKc2x3j.mjs +10 -0
- package/dist/prepare-pwa-context.d.mts +11 -0
- package/dist/prepare-pwa-context.mjs +135 -0
- package/dist/prepare-sw-names.d.mts +11 -0
- package/dist/prepare-sw-names.mjs +45 -0
- package/dist/pwa-assets/build.d.mts +9 -0
- package/dist/pwa-assets/build.mjs +15 -0
- package/dist/pwa-assets/config.d.mts +10 -0
- package/dist/pwa-assets/config.mjs +136 -0
- package/dist/pwa-assets/dev.d.mts +11 -0
- package/dist/pwa-assets/dev.mjs +35 -0
- package/dist/pwa-assets/generator.d.mts +20 -0
- package/dist/pwa-assets/generator.mjs +31 -0
- package/dist/pwa-assets/html.d.mts +11 -0
- package/dist/pwa-assets/html.mjs +47 -0
- package/dist/pwa-assets/manifest.d.mts +10 -0
- package/dist/pwa-assets/manifest.mjs +15 -0
- package/dist/pwa-assets/options.d.mts +9 -0
- package/dist/pwa-assets/options.mjs +34 -0
- package/dist/pwa-assets/types.d.mts +9 -0
- package/dist/pwa-assets/utils.d.mts +11 -0
- package/dist/pwa-assets/utils.mjs +48 -0
- package/dist/resolve-inspector-dist.d.mts +11 -0
- package/dist/resolve-inspector-dist.mjs +25 -0
- package/dist/types-B60e7Nq4.d.mts +67 -0
- package/dist/types-BhwjnGLn.d.mts +703 -0
- package/info.d.ts +71 -0
- package/package.json +133 -7
- package/preact.d.ts +17 -0
- package/pwa-assets.d.ts +40 -0
- package/react-legacy.d.ts +22 -0
- package/react.d.ts +17 -0
- package/solid.d.ts +17 -0
- package/svelte.d.ts +17 -0
- package/types/index.d.ts +43 -0
- package/types/package.json +3 -0
- package/vanillajs.d.ts +13 -0
- package/vue.d.ts +17 -0
- package/index.js +0 -1
package/dist/config.mjs
ADDED
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
MIT License
|
|
3
|
+
|
|
4
|
+
Copyright (c) 2020-PRESENT Anthony Fu <https://github.com/antfu>
|
|
5
|
+
|
|
6
|
+
https://github.com/userquin/quini-pwa-monorepo/blob/main/LICENSE.
|
|
7
|
+
*/
|
|
8
|
+
import { resolvePWAAssetsOptions } from "./pwa-assets/options.mjs";
|
|
9
|
+
import { normalizePath } from "@vite-pwa/workbox-build/utils/resolve-sw-names";
|
|
10
|
+
import fs from "node:fs";
|
|
11
|
+
import path from "node:path";
|
|
12
|
+
import process from "node:process";
|
|
13
|
+
import { pathToFileURL } from "node:url";
|
|
14
|
+
import { errStyle } from "@vite-pwa/workbox-build/utils/colors";
|
|
15
|
+
// src/config.ts
|
|
16
|
+
function deepMergeObject(magicast, object) {
|
|
17
|
+
if (typeof object === "object" && object !== null) for (const key in object) {
|
|
18
|
+
const magicastValue = magicast[key];
|
|
19
|
+
const objectValue = object[key];
|
|
20
|
+
if (magicastValue === objectValue) continue;
|
|
21
|
+
if (typeof magicastValue === "object" && magicastValue !== null && typeof objectValue === "object" && objectValue !== null) deepMergeObject(magicastValue, objectValue);
|
|
22
|
+
else magicast[key] = objectValue;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
const DEFAULT_CONFIG_FILES = [
|
|
26
|
+
"pwa.config.js",
|
|
27
|
+
"pwa.config.ts",
|
|
28
|
+
"pwa.config.mjs",
|
|
29
|
+
"pwa.config.mts"
|
|
30
|
+
];
|
|
31
|
+
/**
|
|
32
|
+
* Loads the PWA configuration from a specified path.
|
|
33
|
+
*
|
|
34
|
+
* If the `path` options is not provided, it will return the provided options as is.
|
|
35
|
+
*
|
|
36
|
+
* Otherwise, it will attempt to load the configuration from the specified path
|
|
37
|
+
* and merge it with the provided options if `mergeOptions` is set to true.
|
|
38
|
+
*
|
|
39
|
+
* @param options The partial PWA options to load.
|
|
40
|
+
* @returns The resolved PWA options, merged with the provided options if `mergeOptions` is set to true.
|
|
41
|
+
*/
|
|
42
|
+
async function loadConfiguration(options) {
|
|
43
|
+
if (!options.path) return options;
|
|
44
|
+
const cwd = path.resolve(process.cwd(), options.cwd || ".");
|
|
45
|
+
const configPath = path.isAbsolute(options.path) ? options.path : path.resolve(cwd, options.path);
|
|
46
|
+
const configModule = await import(pathToFileURL(configPath).href).then((m) => m.default ?? m.options ?? m.config ?? m);
|
|
47
|
+
const external = typeof configModule === "function" ? await configModule() : configModule;
|
|
48
|
+
if (options.mergeOptions) deepMergeObject(external, options);
|
|
49
|
+
external.path = normalizePath(configPath);
|
|
50
|
+
return external;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Loads the first existing default configuration file from the current working directory.
|
|
54
|
+
*
|
|
55
|
+
* The default configuration files are searched in the following order:
|
|
56
|
+
* - `pwa.config.js`
|
|
57
|
+
* - `pwa.config.ts`
|
|
58
|
+
* - `pwa.config.mjs`
|
|
59
|
+
* - `pwa.config.mts`
|
|
60
|
+
*
|
|
61
|
+
* @param cwd The current working directory to search for the default configuration files. Defaults to `process.cwd()`.
|
|
62
|
+
* @returns The path to the first existing default configuration file, or `undefined` if none are found.
|
|
63
|
+
*/
|
|
64
|
+
function resolveDefaultConfig(cwd = process.cwd()) {
|
|
65
|
+
for (const name of DEFAULT_CONFIG_FILES) {
|
|
66
|
+
const candidate = path.resolve(cwd, name);
|
|
67
|
+
if (fs.existsSync(candidate)) return candidate;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Loads the default manifest using the `package.json` file.
|
|
72
|
+
*
|
|
73
|
+
* @param options The resolved PWA options.
|
|
74
|
+
*/
|
|
75
|
+
function prepareManifest(options) {
|
|
76
|
+
if (options.manifest === false) return;
|
|
77
|
+
const pkg = fs.existsSync("package.json") ? JSON.parse(fs.readFileSync("package.json", "utf-8")) : {};
|
|
78
|
+
options.manifest = Object.assign({}, {
|
|
79
|
+
name: pkg.name,
|
|
80
|
+
short_name: pkg.name,
|
|
81
|
+
description: pkg.description,
|
|
82
|
+
start_url: options.base,
|
|
83
|
+
display: "standalone",
|
|
84
|
+
background_color: "#ffffff",
|
|
85
|
+
theme_color: "#42b883",
|
|
86
|
+
lang: "en",
|
|
87
|
+
scope: options.scope
|
|
88
|
+
}, options.manifest ?? {});
|
|
89
|
+
}
|
|
90
|
+
function checkInjectRegister(strategy, injectRegister, swType, color, buildWarning) {
|
|
91
|
+
return swType === "classic-and-module" && injectRegister === "inline" ? [
|
|
92
|
+
`\n${errStyle([color, "bold"], "[Vite PWA]")} ${errStyle(color, "WRONG CONFIGURATION")}:`,
|
|
93
|
+
`You are using ${errStyle("cyan", "inline")} for inject register with dual service worker registration.`,
|
|
94
|
+
`Specify other value at ${errStyle("cyan", "injectRegister")} option${buildWarning}.\n`
|
|
95
|
+
].join("\n") : void 0;
|
|
96
|
+
}
|
|
97
|
+
function checkOptions(isDev, consumerOptions, resolvedOptions) {
|
|
98
|
+
const isDevEnabled = consumerOptions.devOptions?.enabled === true;
|
|
99
|
+
const isWarning = isDev && !isDevEnabled;
|
|
100
|
+
const color = isWarning ? "yellow" : "red";
|
|
101
|
+
const warning = isWarning ? `, ${errStyle("yellow", "running build command will fail")}` : "";
|
|
102
|
+
let message;
|
|
103
|
+
switch (resolvedOptions.strategy) {
|
|
104
|
+
case "inject-manifest": {
|
|
105
|
+
const { swType } = resolvedOptions.injectManifest;
|
|
106
|
+
if (swType === "classic-and-module") message = [
|
|
107
|
+
`\n${errStyle([color, "bold"], "[Vite PWA]")} ${errStyle(color, "WRONG CONFIGURATION")}:`,
|
|
108
|
+
`You are using ${errStyle("cyan", String(consumerOptions.strategies))} with ${errStyle("cyan", swType)} service worker type.`,
|
|
109
|
+
`Specify ${errStyle("green", "classic")} or ${errStyle("green", "module")} at ${errStyle("cyan", "swType")} option${warning}.\n`
|
|
110
|
+
].join("\n");
|
|
111
|
+
break;
|
|
112
|
+
}
|
|
113
|
+
case "generate-sw":
|
|
114
|
+
message = checkInjectRegister("generate-sw", resolvedOptions.injectRegister, resolvedOptions.generateSW.swType, color, warning);
|
|
115
|
+
break;
|
|
116
|
+
case "build-sw": message = checkInjectRegister("build-sw", consumerOptions.injectRegister, resolvedOptions.buildSW.swType, color, warning);
|
|
117
|
+
}
|
|
118
|
+
if (message) {
|
|
119
|
+
if (isWarning) console.warn(message);
|
|
120
|
+
else throw new Error(message);
|
|
121
|
+
}
|
|
122
|
+
return resolvedOptions;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Resolves the PWA configuration based on the provided options and resolver options.
|
|
126
|
+
*
|
|
127
|
+
* This function will search for the PWA configuration file if the `path` option is not provided,
|
|
128
|
+
* and will merge the loaded configuration with the provided options.
|
|
129
|
+
*
|
|
130
|
+
* When using `inject-manifest`, the `resolverOptions.isWrongInjectManifest` callback must resolve if the strategy is wrong, the implementation should be:
|
|
131
|
+
* - if the service worker with `.ts` or `.mts` extension, then, it is `build-sw` and not `inject-manifest` strategy: must return true
|
|
132
|
+
* - if the service worker outside public dir, then, it is `build-sw` and not `inject-manifest` strategy: must return true
|
|
133
|
+
* - otherwise must return false
|
|
134
|
+
*
|
|
135
|
+
* @param pwaOptions The PWA options to resolve.
|
|
136
|
+
* @param resolverOptions The resolver options containing environment information and callbacks.
|
|
137
|
+
* @returns The resolved PWA options.
|
|
138
|
+
*/
|
|
139
|
+
async function resolvePwaConfiguration(pwaOptions, resolverOptions) {
|
|
140
|
+
const resolvedPath = pwaOptions.path ?? resolveDefaultConfig(pwaOptions.cwd);
|
|
141
|
+
const { pwaAssets, filename = "sw.js", strategies = "generateSW", swType = "classic", includeManifest = true, includeManifestIcons = true, includeManifestShortcutIcons = true, includeManifestScreenshots = false, disable = false, injectRegister = "auto", registerType = "prompt", useCredentials = false, manifestFilename = "manifest.webmanifest", minify, maximumFileSizeToCacheInBytes, throwMaximumFileSizeToCacheInBytes, additionalManifestEntries, additionalManifestEntriesGenerator, manifest, updateViaCache = "imports", ...rest } = await loadConfiguration(Object.assign({}, pwaOptions, { path: resolvedPath }));
|
|
142
|
+
const resolvedPwaAssets = resolvePWAAssetsOptions(pwaAssets);
|
|
143
|
+
switch (strategies) {
|
|
144
|
+
case "generateSW":
|
|
145
|
+
case "generate-sw": {
|
|
146
|
+
const { workbox, generateSW, ...strategyOptions } = rest;
|
|
147
|
+
if (workbox && !generateSW) console.warn([
|
|
148
|
+
`\n${errStyle(["yellow", "bold"], "[Vite PWA]")} ${errStyle("yellow", "DEPRECATION WARNING")}:`,
|
|
149
|
+
`You are using ${errStyle("cyan", "workbox")} option, which is now deprecated.`,
|
|
150
|
+
`Please replace ${errStyle("cyan", "workbox")} with ${errStyle("green", "generateSW")} option.`,
|
|
151
|
+
`${errStyle("cyan", "workbox")} option will be removed in the next major version.\n`
|
|
152
|
+
].join("\n"));
|
|
153
|
+
const { inlineWorkboxRuntime = false, workboxRuntimeCompatible = true, ...generateSWOptions } = generateSW ?? workbox ?? {};
|
|
154
|
+
return checkOptions(resolverOptions.isDev, pwaOptions, Object.assign({}, strategyOptions, {
|
|
155
|
+
strategy: "generate-sw",
|
|
156
|
+
swType,
|
|
157
|
+
includeManifest,
|
|
158
|
+
includeManifestIcons,
|
|
159
|
+
includeManifestShortcutIcons,
|
|
160
|
+
includeManifestScreenshots,
|
|
161
|
+
disable,
|
|
162
|
+
injectRegister,
|
|
163
|
+
registerType,
|
|
164
|
+
useCredentials,
|
|
165
|
+
manifest,
|
|
166
|
+
manifestFilename,
|
|
167
|
+
minify,
|
|
168
|
+
updateViaCache,
|
|
169
|
+
pwaAssets: resolvedPwaAssets
|
|
170
|
+
}, { generateSW: Object.assign(generateSWOptions, {
|
|
171
|
+
inlineWorkboxRuntime,
|
|
172
|
+
workboxRuntimeCompatible,
|
|
173
|
+
swDest: filename,
|
|
174
|
+
swType,
|
|
175
|
+
minify,
|
|
176
|
+
maximumFileSizeToCacheInBytes,
|
|
177
|
+
throwMaximumFileSizeToCacheInBytes,
|
|
178
|
+
additionalManifestEntries,
|
|
179
|
+
additionalManifestEntriesGenerator
|
|
180
|
+
}) }));
|
|
181
|
+
}
|
|
182
|
+
case "injectManifest":
|
|
183
|
+
case "inject-manifest": {
|
|
184
|
+
const swSrcName = pwaOptions.injectManifest?.swSrc;
|
|
185
|
+
if (!swSrcName) throw new Error([`\n${errStyle(["red", "bold"], "[Vite PWA]")} ${errStyle("red", "WRONG CONFIGURATION")}:`, `You are using ${errStyle("cyan", strategies)} option without ${errStyle("cyan", "swSrc")} option.\n`].join("\n"));
|
|
186
|
+
const isTS = swSrcName.endsWith(".ts") || swSrcName.endsWith(".mts");
|
|
187
|
+
if (isTS || await resolverOptions.isWrongInjectManifest(normalizePath(path.resolve(process.cwd(), swSrcName)))) {
|
|
188
|
+
const isWarning = resolverOptions.isDev && !(pwaOptions?.devOptions?.enabled === true);
|
|
189
|
+
const warning = isWarning ? `, ${errStyle("yellow", "running build command will fail")}` : "";
|
|
190
|
+
const color = isWarning ? "yellow" : "red";
|
|
191
|
+
const message = [
|
|
192
|
+
`\n${errStyle([color, "bold"], "[Vite PWA]")} ${errStyle(color, "WRONG CONFIGURATION")}:`,
|
|
193
|
+
`You are using ${errStyle("cyan", strategies)} option with a service worker ${isTS ? "using TypeScript" : "as static asset"}.`,
|
|
194
|
+
`Please migrate to ${errStyle("green", "buildSW")} option${warning}.`,
|
|
195
|
+
`${errStyle("cyan", strategies)} option should be only used when you need to inject a manifest into an existing service worker.\n`
|
|
196
|
+
].join("\n");
|
|
197
|
+
if (isWarning) console.warn(message);
|
|
198
|
+
else throw new Error(message);
|
|
199
|
+
return checkOptions(resolverOptions.isDev, pwaOptions, Object.assign({}, rest, {
|
|
200
|
+
strategy: "build-sw",
|
|
201
|
+
swType,
|
|
202
|
+
includeManifest,
|
|
203
|
+
includeManifestIcons,
|
|
204
|
+
includeManifestShortcutIcons,
|
|
205
|
+
includeManifestScreenshots,
|
|
206
|
+
disable,
|
|
207
|
+
injectRegister,
|
|
208
|
+
registerType,
|
|
209
|
+
useCredentials,
|
|
210
|
+
manifest,
|
|
211
|
+
manifestFilename,
|
|
212
|
+
minify,
|
|
213
|
+
updateViaCache,
|
|
214
|
+
pwaAssets: resolvedPwaAssets
|
|
215
|
+
}, { buildSW: Object.assign(rest.injectManifest ?? {}, {
|
|
216
|
+
swDest: filename,
|
|
217
|
+
swType,
|
|
218
|
+
minify,
|
|
219
|
+
maximumFileSizeToCacheInBytes,
|
|
220
|
+
throwMaximumFileSizeToCacheInBytes,
|
|
221
|
+
additionalManifestEntries,
|
|
222
|
+
additionalManifestEntriesGenerator
|
|
223
|
+
}) }));
|
|
224
|
+
}
|
|
225
|
+
return checkOptions(resolverOptions.isDev, pwaOptions, Object.assign({}, rest, {
|
|
226
|
+
strategy: "inject-manifest",
|
|
227
|
+
swType,
|
|
228
|
+
includeManifest,
|
|
229
|
+
includeManifestIcons,
|
|
230
|
+
includeManifestShortcutIcons,
|
|
231
|
+
includeManifestScreenshots,
|
|
232
|
+
disable,
|
|
233
|
+
injectRegister,
|
|
234
|
+
registerType,
|
|
235
|
+
useCredentials,
|
|
236
|
+
manifest,
|
|
237
|
+
manifestFilename,
|
|
238
|
+
minify,
|
|
239
|
+
updateViaCache,
|
|
240
|
+
pwaAssets: resolvedPwaAssets
|
|
241
|
+
}, { injectManifest: Object.assign(rest.injectManifest ?? {}, {
|
|
242
|
+
swDest: filename,
|
|
243
|
+
maximumFileSizeToCacheInBytes,
|
|
244
|
+
throwMaximumFileSizeToCacheInBytes,
|
|
245
|
+
additionalManifestEntries,
|
|
246
|
+
additionalManifestEntriesGenerator
|
|
247
|
+
}) }));
|
|
248
|
+
}
|
|
249
|
+
case "build-sw":
|
|
250
|
+
case "buildSW": {
|
|
251
|
+
const { inlineWorkboxRuntime = true, workboxRuntimeCompatible = true, ...buildSWOptions } = rest.buildSW ?? {};
|
|
252
|
+
return checkOptions(resolverOptions.isDev, pwaOptions, Object.assign({}, rest, {
|
|
253
|
+
strategy: "build-sw",
|
|
254
|
+
swType,
|
|
255
|
+
includeManifest,
|
|
256
|
+
includeManifestIcons,
|
|
257
|
+
includeManifestShortcutIcons,
|
|
258
|
+
includeManifestScreenshots,
|
|
259
|
+
disable,
|
|
260
|
+
injectRegister,
|
|
261
|
+
registerType,
|
|
262
|
+
useCredentials,
|
|
263
|
+
manifest,
|
|
264
|
+
manifestFilename,
|
|
265
|
+
minify,
|
|
266
|
+
updateViaCache,
|
|
267
|
+
pwaAssets: resolvedPwaAssets
|
|
268
|
+
}, { buildSW: Object.assign(buildSWOptions, {
|
|
269
|
+
inlineWorkboxRuntime,
|
|
270
|
+
workboxRuntimeCompatible,
|
|
271
|
+
swDest: filename,
|
|
272
|
+
swType,
|
|
273
|
+
minify,
|
|
274
|
+
maximumFileSizeToCacheInBytes,
|
|
275
|
+
throwMaximumFileSizeToCacheInBytes,
|
|
276
|
+
additionalManifestEntries,
|
|
277
|
+
additionalManifestEntriesGenerator
|
|
278
|
+
}) }));
|
|
279
|
+
}
|
|
280
|
+
case "self-destroy-sw":
|
|
281
|
+
case "selfDestroySW": throw new Error([
|
|
282
|
+
`\n${errStyle(["red", "bold"], "[Vite PWA] self-destroying")} ${errStyle("red", "strategy is no longer supported directly in the build process.")}`,
|
|
283
|
+
" It has been replaced by an interactive Self Destroying SW CLI. This tool will safely generate",
|
|
284
|
+
" the necessary auto-destroying Service Workers for your specific setup (including dual classic/ESM builds)",
|
|
285
|
+
" and update your config automatically.",
|
|
286
|
+
" The Self Destroying SW CLI is not yet available, in the meantime check:",
|
|
287
|
+
" https://github.com/vite-pwa/unplugin-pwa/blob/main/packages/vite/BREAKING-CHANGES.md#1-do-i-need-to-change-my-service-worker-setup-read-this-first",
|
|
288
|
+
"\n"
|
|
289
|
+
].join("\n"));
|
|
290
|
+
}
|
|
291
|
+
throw new Error("Unknown strategy, please use one of the following: \"generateSW\", \"injectManifest\", \"buildSW\"");
|
|
292
|
+
}
|
|
293
|
+
export { DEFAULT_CONFIG_FILES, loadConfiguration, prepareManifest, resolveDefaultConfig, resolvePwaConfiguration };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
MIT License
|
|
3
|
+
|
|
4
|
+
Copyright (c) 2020-PRESENT Anthony Fu <https://github.com/antfu>
|
|
5
|
+
|
|
6
|
+
https://github.com/userquin/quini-pwa-monorepo/blob/main/LICENSE.
|
|
7
|
+
*/
|
|
8
|
+
export declare const FILE_SW_REGISTER = "registerSW.js";
|
|
9
|
+
export declare const VIRTUAL_MODULES_MAP: Record<string, string>;
|
|
10
|
+
export declare const VIRTUAL_MODULES_RESOLVED_PREFIX = "/@unplugin-pwa/";
|
|
11
|
+
export declare const VIRTUAL_MODULES: string[];
|
|
12
|
+
export declare const PWA_INFO_VIRTUAL = "virtual:pwa-info";
|
|
13
|
+
export declare const RESOLVED_PWA_INFO_VIRTUAL = "\0virtual:pwa-info";
|
|
14
|
+
export declare const PWA_ASSETS_HEAD_VIRTUAL = "virtual:pwa-assets/head";
|
|
15
|
+
export declare const RESOLVED_PWA_ASSETS_HEAD_VIRTUAL = "\0virtual:pwa-assets/head";
|
|
16
|
+
export declare const PWA_ASSETS_ICONS_VIRTUAL = "virtual:pwa-assets/icons";
|
|
17
|
+
export declare const RESOLVED_PWA_ASSETS_ICONS_VIRTUAL = "\0virtual:pwa-assets/icons";
|
|
18
|
+
export declare const DEV_SW_NAME = "dev-sw.js?dev-sw";
|
|
19
|
+
export declare const DEV_SW_VIRTUAL = "/@unplugin-pwa/pwa-entry-point-loaded";
|
|
20
|
+
export declare const DEV_SW_VIRTUAL_VIRTUAL = "virtual:pwa-entry-point-loaded";
|
|
21
|
+
export declare const RESOLVED_DEV_SW_VIRTUAL_VIRTUAL = "\0virtual:pwa-entry-point-loaded";
|
|
22
|
+
export declare const RESOLVED_DEV_SW_VIRTUAL = "\0/@unplugin-pwa/pwa-entry-point-loaded";
|
|
23
|
+
export declare const DEV_READY_NAME = "unplugin-pwa:dev-ready";
|
|
24
|
+
export declare const DEV_REGISTER_SW_NAME = "unplugin-pwa:register-sw";
|
|
25
|
+
export declare const DEV_PWA_ASSETS_NAME = "unplugin-pwa:pwa-assets";
|
|
26
|
+
export declare const DEV_SWITCHER_NAME = "unplugin-pwa:pwa-switcher";
|
|
27
|
+
export declare const DEV_PWA_DUAL_SW_SWITCHER_NAME = "./switcher.js";
|
|
28
|
+
export declare const DEV_PWA_REGISTER_NAME = "./register.js";
|
|
29
|
+
export declare const INSPECTOR_BASE_PATH = "/__unplugin_pwa_inspector";
|
|
30
|
+
export declare const INSPECTOR_BASE_PATH_URL = "/__unplugin_pwa_inspector/";
|
|
31
|
+
export declare const INSPECTOR_BASE_PATH_API = "/__unplugin_pwa_inspector_api";
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
MIT License
|
|
3
|
+
|
|
4
|
+
Copyright (c) 2020-PRESENT Anthony Fu <https://github.com/antfu>
|
|
5
|
+
|
|
6
|
+
https://github.com/userquin/quini-pwa-monorepo/blob/main/LICENSE.
|
|
7
|
+
*/
|
|
8
|
+
// src/constants.ts
|
|
9
|
+
const FILE_SW_REGISTER = "registerSW.js";
|
|
10
|
+
const VIRTUAL_MODULES_MAP = {
|
|
11
|
+
"virtual:pwa-register": "register",
|
|
12
|
+
"virtual:pwa-register/vue": "vue",
|
|
13
|
+
"virtual:pwa-register/svelte": "svelte",
|
|
14
|
+
"virtual:pwa-register/react": "react",
|
|
15
|
+
"virtual:pwa-register/react-legacy": "react-legacy",
|
|
16
|
+
"virtual:pwa-register/preact": "preact",
|
|
17
|
+
"virtual:pwa-register/solid": "solid"
|
|
18
|
+
};
|
|
19
|
+
const VIRTUAL_MODULES_RESOLVED_PREFIX = "/@unplugin-pwa/";
|
|
20
|
+
const VIRTUAL_MODULES = /* @__PURE__ */ Object.keys(VIRTUAL_MODULES_MAP);
|
|
21
|
+
const PWA_INFO_VIRTUAL = "virtual:pwa-info";
|
|
22
|
+
const RESOLVED_PWA_INFO_VIRTUAL = `\0${PWA_INFO_VIRTUAL}`;
|
|
23
|
+
const PWA_ASSETS_HEAD_VIRTUAL = "virtual:pwa-assets/head";
|
|
24
|
+
const RESOLVED_PWA_ASSETS_HEAD_VIRTUAL = `\0${PWA_ASSETS_HEAD_VIRTUAL}`;
|
|
25
|
+
const PWA_ASSETS_ICONS_VIRTUAL = "virtual:pwa-assets/icons";
|
|
26
|
+
const RESOLVED_PWA_ASSETS_ICONS_VIRTUAL = `\0${PWA_ASSETS_ICONS_VIRTUAL}`;
|
|
27
|
+
const DEV_SW_NAME = "dev-sw.js?dev-sw";
|
|
28
|
+
const DEV_SW_VIRTUAL = `${VIRTUAL_MODULES_RESOLVED_PREFIX}pwa-entry-point-loaded`;
|
|
29
|
+
const DEV_SW_VIRTUAL_VIRTUAL = "virtual:pwa-entry-point-loaded";
|
|
30
|
+
const RESOLVED_DEV_SW_VIRTUAL_VIRTUAL = `\0${DEV_SW_VIRTUAL_VIRTUAL}`;
|
|
31
|
+
const RESOLVED_DEV_SW_VIRTUAL = `\0${DEV_SW_VIRTUAL}`;
|
|
32
|
+
const DEV_READY_NAME = "unplugin-pwa:dev-ready";
|
|
33
|
+
const DEV_REGISTER_SW_NAME = "unplugin-pwa:register-sw";
|
|
34
|
+
const DEV_PWA_ASSETS_NAME = "unplugin-pwa:pwa-assets";
|
|
35
|
+
const DEV_SWITCHER_NAME = "unplugin-pwa:pwa-switcher";
|
|
36
|
+
const DEV_PWA_DUAL_SW_SWITCHER_NAME = "./switcher.js";
|
|
37
|
+
const DEV_PWA_REGISTER_NAME = "./register.js";
|
|
38
|
+
const INSPECTOR_BASE_PATH = "/__unplugin_pwa_inspector";
|
|
39
|
+
const INSPECTOR_BASE_PATH_URL = `${INSPECTOR_BASE_PATH}/`;
|
|
40
|
+
const INSPECTOR_BASE_PATH_API = `${INSPECTOR_BASE_PATH}_api`;
|
|
41
|
+
export { DEV_PWA_ASSETS_NAME, DEV_PWA_DUAL_SW_SWITCHER_NAME, DEV_PWA_REGISTER_NAME, DEV_READY_NAME, DEV_REGISTER_SW_NAME, DEV_SWITCHER_NAME, DEV_SW_NAME, DEV_SW_VIRTUAL, DEV_SW_VIRTUAL_VIRTUAL, FILE_SW_REGISTER, INSPECTOR_BASE_PATH, INSPECTOR_BASE_PATH_API, INSPECTOR_BASE_PATH_URL, PWA_ASSETS_HEAD_VIRTUAL, PWA_ASSETS_ICONS_VIRTUAL, PWA_INFO_VIRTUAL, RESOLVED_DEV_SW_VIRTUAL, RESOLVED_DEV_SW_VIRTUAL_VIRTUAL, RESOLVED_PWA_ASSETS_HEAD_VIRTUAL, RESOLVED_PWA_ASSETS_ICONS_VIRTUAL, RESOLVED_PWA_INFO_VIRTUAL, VIRTUAL_MODULES, VIRTUAL_MODULES_MAP, VIRTUAL_MODULES_RESOLVED_PREFIX };
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
MIT License
|
|
3
|
+
|
|
4
|
+
Copyright (c) 2020-PRESENT Anthony Fu <https://github.com/antfu>
|
|
5
|
+
|
|
6
|
+
https://github.com/userquin/quini-pwa-monorepo/blob/main/LICENSE.
|
|
7
|
+
*/
|
|
8
|
+
import { r as PWAAssetsGenerator } from "./types-B60e7Nq4.mjs";
|
|
9
|
+
import { C as VitePWAOptions, T as WebManifestData, m as RegisterSWData, w as VitePWAStrategy, y as ResolvedVitePWAOptions } from "./types-BhwjnGLn.mjs";
|
|
10
|
+
import { Hookable } from "hookable";
|
|
11
|
+
import { BuildResult, SWType } from "@vite-pwa/workbox-build/types";
|
|
12
|
+
import { BuildGenerateSWOptions, BuildWithSourcesResult } from "@vite-pwa/workbox-build/build/types";
|
|
13
|
+
import { InjectManifestStrategyOptions, SelfDestroyingStrategyOptions } from "@vite-pwa/workbox-build/config/types";
|
|
14
|
+
export type Bundler = 'vite' | 'vite-legacy' | 'webpack' | 'rspack';
|
|
15
|
+
export type BuildSWType<B extends Bundler, T extends SWType> = B extends 'vite' ? import('@vite-pwa/workbox-build/build/vite/types').BuildServiceWorkerOptions<T> : B extends 'vite-legacy' ? import('@vite-pwa/workbox-build/build/vite/legacy-types').LegacyBuildServiceWorkerOptions<T> : import('@vite-pwa/workbox-build/build/rolldown/types').BuildServiceWorkerOptions<T>;
|
|
16
|
+
export type ExtractStrategy<UserStrategy extends VitePWAStrategy> = UserStrategy extends 'generateSW' ? 'generate-sw' : UserStrategy extends 'generate-sw' ? 'generate-sw' : UserStrategy extends 'buildSW' ? 'build-sw' : UserStrategy extends 'build-sw' ? 'build-sw' : UserStrategy extends 'injectManifest' ? 'inject-manifest' : UserStrategy extends 'inject-manifest' ? 'inject-manifest' : UserStrategy extends 'selfDestroySW' ? 'self-destroy-sw' : UserStrategy extends 'self-destroy-sw' ? 'self-destroy-sw' : 'generate-sw';
|
|
17
|
+
export interface PWABuildContext {
|
|
18
|
+
generateSW: () => Promise<BuildResult>;
|
|
19
|
+
buildSW: () => Promise<BuildWithSourcesResult>;
|
|
20
|
+
injectManifest: () => Promise<BuildResult>;
|
|
21
|
+
selfDestroyingSW: () => Promise<boolean>;
|
|
22
|
+
}
|
|
23
|
+
export interface SWNames {
|
|
24
|
+
hasNames: boolean;
|
|
25
|
+
name: string;
|
|
26
|
+
classic: string;
|
|
27
|
+
module: string;
|
|
28
|
+
}
|
|
29
|
+
export interface DevSWNames extends SWNames {
|
|
30
|
+
path: string;
|
|
31
|
+
classicPath: string;
|
|
32
|
+
modulePath: string;
|
|
33
|
+
devSWDest: string;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* The type of PWA asset.
|
|
37
|
+
*/
|
|
38
|
+
export type PwaAsset = 'register-sw' | 'virtual-register-sw';
|
|
39
|
+
/**
|
|
40
|
+
* Custom PWA asset resolver for `registerSW.js` and PWA virtual modules.
|
|
41
|
+
*
|
|
42
|
+
* When `virtual-register-sw` the virtualName won't be undefined:
|
|
43
|
+
* - 'register' for `virtual:pwa-register`
|
|
44
|
+
* - 'vue' for `virtual:pwa-register/vue`
|
|
45
|
+
* - 'svelte' for `virtual:pwa-register/svelte`
|
|
46
|
+
* - 'react' for `virtual:pwa-register/react`
|
|
47
|
+
* - 'react-legacy' for `virtual:pwa-register/react-legacy`
|
|
48
|
+
* - 'preact' for `virtual:pwa-register/preact`
|
|
49
|
+
* - 'solid' for `virtual:pwa-register/solid`
|
|
50
|
+
*
|
|
51
|
+
* @param asset The asset type to resolve
|
|
52
|
+
* @param virtualName The virtual module name when asset is `virtual-register-sw`
|
|
53
|
+
* @return The generated PWA asset
|
|
54
|
+
*/
|
|
55
|
+
export type CustomPwaAssetResolver = (asset: PwaAsset, virtualName?: string) => Promise<string>;
|
|
56
|
+
export interface PWABuildDevContext<B extends Bundler, T extends SWType> {
|
|
57
|
+
options: {
|
|
58
|
+
/**
|
|
59
|
+
* The current service worker name.
|
|
60
|
+
*/
|
|
61
|
+
swName: string;
|
|
62
|
+
/**
|
|
63
|
+
* The current service worker type.
|
|
64
|
+
*/
|
|
65
|
+
swType: WorkerType;
|
|
66
|
+
swGenerated: boolean;
|
|
67
|
+
registerSWGenerated: boolean;
|
|
68
|
+
registerVirtualSWGenerated: boolean;
|
|
69
|
+
hmrEntryPointGenerated: boolean;
|
|
70
|
+
navigateFallbackAllowlist?: RegExp[];
|
|
71
|
+
swAssetKeys: Set<string>;
|
|
72
|
+
swAssetsPaths: Map<string, string>;
|
|
73
|
+
tempFolder: string;
|
|
74
|
+
/**
|
|
75
|
+
* Hook to allow remove prefixes: for example _nuxt/
|
|
76
|
+
*/
|
|
77
|
+
mapSWSourcemapFile?: (url: string) => string | undefined;
|
|
78
|
+
/**
|
|
79
|
+
* Names and paths to resolve service workers.
|
|
80
|
+
*/
|
|
81
|
+
swNames: DevSWNames;
|
|
82
|
+
/**
|
|
83
|
+
* The globDirectory to cache only entry point.
|
|
84
|
+
*/
|
|
85
|
+
globDirectory: string;
|
|
86
|
+
};
|
|
87
|
+
generateSW: (options: Partial<BuildGenerateSWOptions<T>>) => Promise<BuildResult>;
|
|
88
|
+
buildSW: (options: Partial<BuildSWType<B, T>>) => Promise<BuildWithSourcesResult>;
|
|
89
|
+
injectManifest: (options: Partial<InjectManifestStrategyOptions>) => Promise<BuildResult>;
|
|
90
|
+
selfDestroyingSW: (options: SelfDestroyingStrategyOptions) => Promise<boolean>;
|
|
91
|
+
}
|
|
92
|
+
export interface ConfigurePWAOptions {
|
|
93
|
+
outDir: string;
|
|
94
|
+
/**
|
|
95
|
+
* Used to generate the dontCache
|
|
96
|
+
*/
|
|
97
|
+
immutableAssets: string;
|
|
98
|
+
cwd: string;
|
|
99
|
+
}
|
|
100
|
+
export type HookResult = void | Promise<void>;
|
|
101
|
+
export interface PWAHooks {
|
|
102
|
+
'context:ready': (error?: unknown) => HookResult;
|
|
103
|
+
'service-worker:generated': () => HookResult;
|
|
104
|
+
'service-worker:switched': () => HookResult;
|
|
105
|
+
}
|
|
106
|
+
export interface PWAPluginContext<B extends Bundler, UserStrategy extends VitePWAStrategy, T extends SWType> {
|
|
107
|
+
bundler: B;
|
|
108
|
+
version: string;
|
|
109
|
+
strategy: ExtractStrategy<UserStrategy>;
|
|
110
|
+
consumerOptions: Partial<VitePWAOptions<UserStrategy, T>>;
|
|
111
|
+
externalConfigurationLoader: boolean;
|
|
112
|
+
resolvedOptions: Partial<ResolvedVitePWAOptions<ExtractStrategy<UserStrategy>, T>>;
|
|
113
|
+
useImportRegister: boolean;
|
|
114
|
+
devEnvironment: boolean;
|
|
115
|
+
isPreview: boolean;
|
|
116
|
+
hmrRequiresSwitcher?: true;
|
|
117
|
+
pwaAssetsGenerator: Promise<PWAAssetsGenerator | undefined>;
|
|
118
|
+
build: PWABuildContext;
|
|
119
|
+
dev: PWABuildDevContext<B, T>;
|
|
120
|
+
publicDir: string;
|
|
121
|
+
rootDir: string;
|
|
122
|
+
outDir: string;
|
|
123
|
+
base: string;
|
|
124
|
+
sources: Set<string>;
|
|
125
|
+
swNames: SWNames;
|
|
126
|
+
/**
|
|
127
|
+
* When using `inject-manifest` this hook will resolve if the service worker is inside public directory.
|
|
128
|
+
*
|
|
129
|
+
* Integrations can override this hook, for example, Vite integration will check the `publicDir`, or Nuxt will
|
|
130
|
+
* check Nitro public dirs.
|
|
131
|
+
*/
|
|
132
|
+
injectManifestSWAtPublicDir: () => boolean;
|
|
133
|
+
/**
|
|
134
|
+
* The custom resolver to resolve PWA assets for `registerSW.js` and virtual PWA modules.
|
|
135
|
+
*/
|
|
136
|
+
customPwaAssetResolver: CustomPwaAssetResolver;
|
|
137
|
+
/**
|
|
138
|
+
* Returns the PWA web manifest url for the manifest link:
|
|
139
|
+
* <link rel="manifest" href="<webManifestUrl>" />
|
|
140
|
+
*
|
|
141
|
+
* Will also return if the manifest will require credentials:
|
|
142
|
+
* <link rel="manifest" href="<webManifestUrl>" crossorigin="use-credentials" />
|
|
143
|
+
*/
|
|
144
|
+
webManifestData: () => WebManifestData | undefined;
|
|
145
|
+
/**
|
|
146
|
+
* How the service worker is being registered in the application.
|
|
147
|
+
*
|
|
148
|
+
* This option will help some integrations to inject the corresponding script in the head.
|
|
149
|
+
*/
|
|
150
|
+
registerSWData: () => Promise<RegisterSWData & {
|
|
151
|
+
module: boolean;
|
|
152
|
+
} | undefined>;
|
|
153
|
+
runBuild: () => Promise<BuildResult | boolean>;
|
|
154
|
+
hooks: Hookable<PWAHooks>;
|
|
155
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
MIT License
|
|
3
|
+
|
|
4
|
+
Copyright (c) 2020-PRESENT Anthony Fu <https://github.com/antfu>
|
|
5
|
+
|
|
6
|
+
https://github.com/userquin/quini-pwa-monorepo/blob/main/LICENSE.
|
|
7
|
+
*/
|
|
8
|
+
import { C as VitePWAOptions, w as VitePWAStrategy } from "./types-BhwjnGLn.mjs";
|
|
9
|
+
import { Bundler, PWAPluginContext } from "./context-types.mjs";
|
|
10
|
+
import { SWType } from "@vite-pwa/workbox-build/types";
|
|
11
|
+
export declare function createPWAContext<B extends Bundler, UserStrategy extends VitePWAStrategy, T extends SWType>(bundler: B, userOptions?: Partial<VitePWAOptions<UserStrategy, T>>): PWAPluginContext<B, UserStrategy, T>;
|
|
12
|
+
export declare function createVitePWAContext<UserStrategy extends VitePWAStrategy, T extends SWType>(userOptions?: Partial<VitePWAOptions<UserStrategy, T>>): PWAPluginContext<'vite', UserStrategy, T>;
|
|
13
|
+
export declare function createViteLegacyPWAContext<UserStrategy extends VitePWAStrategy, T extends SWType>(userOptions?: Partial<VitePWAOptions<UserStrategy, T>>): PWAPluginContext<'vite-legacy', UserStrategy, T>;
|
|
14
|
+
export declare function createWebpackPWAContext<UserStrategy extends VitePWAStrategy, T extends SWType>(userOptions?: Partial<VitePWAOptions<UserStrategy, T>>): PWAPluginContext<'webpack', UserStrategy, T>;
|
|
15
|
+
export declare function createRspackPWAContext<UserStrategy extends VitePWAStrategy, T extends SWType>(userOptions?: Partial<VitePWAOptions<UserStrategy, T>>): PWAPluginContext<'rspack', UserStrategy, T>;
|
package/dist/context.mjs
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
MIT License
|
|
3
|
+
|
|
4
|
+
Copyright (c) 2020-PRESENT Anthony Fu <https://github.com/antfu>
|
|
5
|
+
|
|
6
|
+
https://github.com/userquin/quini-pwa-monorepo/blob/main/LICENSE.
|
|
7
|
+
*/
|
|
8
|
+
import { t as version } from "./package-DpKc2x3j.mjs";
|
|
9
|
+
import { preparePWAContext } from "./prepare-pwa-context.mjs";
|
|
10
|
+
import process from "node:process";
|
|
11
|
+
import { Hookable } from "hookable";
|
|
12
|
+
// src/context.ts
|
|
13
|
+
function createPWAContext(bundler, userOptions = {}) {
|
|
14
|
+
return preparePWAContext({
|
|
15
|
+
bundler,
|
|
16
|
+
version,
|
|
17
|
+
strategy: void 0,
|
|
18
|
+
consumerOptions: userOptions,
|
|
19
|
+
externalConfigurationLoader: false,
|
|
20
|
+
resolvedOptions: void 0,
|
|
21
|
+
useImportRegister: false,
|
|
22
|
+
devEnvironment: false,
|
|
23
|
+
isPreview: false,
|
|
24
|
+
pwaAssetsGenerator: Promise.resolve(void 0),
|
|
25
|
+
build: void 0,
|
|
26
|
+
dev: void 0,
|
|
27
|
+
base: void 0,
|
|
28
|
+
swNames: {
|
|
29
|
+
hasNames: false,
|
|
30
|
+
name: "",
|
|
31
|
+
classic: "",
|
|
32
|
+
module: ""
|
|
33
|
+
},
|
|
34
|
+
sources: /* @__PURE__ */ new Set(),
|
|
35
|
+
outDir: void 0,
|
|
36
|
+
publicDir: void 0,
|
|
37
|
+
rootDir: process.cwd(),
|
|
38
|
+
customPwaAssetResolver: void 0,
|
|
39
|
+
webManifestData: void 0,
|
|
40
|
+
registerSWData: void 0,
|
|
41
|
+
runBuild: void 0,
|
|
42
|
+
injectManifestSWAtPublicDir: void 0,
|
|
43
|
+
hooks: new Hookable()
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
function createVitePWAContext(userOptions = {}) {
|
|
47
|
+
return createPWAContext("vite", userOptions);
|
|
48
|
+
}
|
|
49
|
+
function createViteLegacyPWAContext(userOptions = {}) {
|
|
50
|
+
return createPWAContext("vite-legacy", userOptions);
|
|
51
|
+
}
|
|
52
|
+
function createWebpackPWAContext(userOptions = {}) {
|
|
53
|
+
return createPWAContext("webpack", userOptions);
|
|
54
|
+
}
|
|
55
|
+
function createRspackPWAContext(userOptions = {}) {
|
|
56
|
+
return createPWAContext("rspack", userOptions);
|
|
57
|
+
}
|
|
58
|
+
export { createPWAContext, createRspackPWAContext, createViteLegacyPWAContext, createVitePWAContext, createWebpackPWAContext };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
MIT License
|
|
3
|
+
|
|
4
|
+
Copyright (c) 2020-PRESENT Anthony Fu <https://github.com/antfu>
|
|
5
|
+
|
|
6
|
+
https://github.com/userquin/quini-pwa-monorepo/blob/main/LICENSE.
|
|
7
|
+
*/
|
|
8
|
+
import { PWAPluginContext } from "./context-types.mjs";
|
|
9
|
+
/**
|
|
10
|
+
* Creates the `registerSW.js` script to be added to the HTML entry point.
|
|
11
|
+
* @param ctx The PWA Context.
|
|
12
|
+
* @param dev For dev server
|
|
13
|
+
* @param injectAtDev Inject the script at dev server?
|
|
14
|
+
*/
|
|
15
|
+
export declare function createGenerateRegisterSW(ctx: PWAPluginContext<any, any, any>, dev: boolean, injectAtDev?: boolean): Promise<string | undefined>;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
MIT License
|
|
3
|
+
|
|
4
|
+
Copyright (c) 2020-PRESENT Anthony Fu <https://github.com/antfu>
|
|
5
|
+
|
|
6
|
+
https://github.com/userquin/quini-pwa-monorepo/blob/main/LICENSE.
|
|
7
|
+
*/
|
|
8
|
+
import { FILE_SW_REGISTER } from "./constants.mjs";
|
|
9
|
+
import { isDualServiceWorker } from "./dual-sw-utilities.mjs";
|
|
10
|
+
import { generateRegisterSW } from "./generate-register-sw.mjs";
|
|
11
|
+
// src/create-generate-register-sw-script.ts
|
|
12
|
+
/**
|
|
13
|
+
* Creates the `registerSW.js` script to be added to the HTML entry point.
|
|
14
|
+
* @param ctx The PWA Context.
|
|
15
|
+
* @param dev For dev server
|
|
16
|
+
* @param injectAtDev Inject the script at dev server?
|
|
17
|
+
*/
|
|
18
|
+
async function createGenerateRegisterSW(ctx, dev, injectAtDev = true) {
|
|
19
|
+
if (dev && !injectAtDev) return;
|
|
20
|
+
const options = isDualServiceWorker(ctx) ? " type=\"module\"" : "";
|
|
21
|
+
if (ctx.resolvedOptions.injectRegister === "inline") return `<script id="unplugin-pwa:inline-sw"${options}>${await generateRegisterSW(ctx)}<\/script>`;
|
|
22
|
+
if (ctx.resolvedOptions.injectRegister === "script" || ctx.resolvedOptions.injectRegister === "script-defer") {
|
|
23
|
+
const hasDefer = ctx.resolvedOptions.injectRegister === "script-defer";
|
|
24
|
+
return `<script id="unplugin-pwa:register-sw" src="${dev ? ctx.resolvedOptions.base : ctx.resolvedOptions.buildBase}${FILE_SW_REGISTER}"${hasDefer ? " defer" : ""}${options}><\/script>`;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
export { createGenerateRegisterSW };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
MIT License
|
|
3
|
+
|
|
4
|
+
Copyright (c) 2020-PRESENT Anthony Fu <https://github.com/antfu>
|
|
5
|
+
|
|
6
|
+
https://github.com/userquin/quini-pwa-monorepo/blob/main/LICENSE.
|
|
7
|
+
*/
|
|
8
|
+
import { PWAPluginContext } from "./context-types.mjs";
|
|
9
|
+
/**
|
|
10
|
+
* Creates the PWA web manifest link to be added to the HTML entry point.
|
|
11
|
+
* @param ctx The PWA Context.
|
|
12
|
+
*/
|
|
13
|
+
export declare function createWebManifestHtmlLink(ctx: PWAPluginContext<any, any, any>): string;
|