@vite-pwa/nuxt 0.10.8 → 1.0.1
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.
|
@@ -3,7 +3,7 @@ import { resolve, relative, basename } from 'node:path';
|
|
|
3
3
|
import process from 'node:process';
|
|
4
4
|
import { instructions } from '@vite-pwa/assets-generator/api/instructions';
|
|
5
5
|
import { loadConfig } from '@vite-pwa/assets-generator/config';
|
|
6
|
-
import { p as pwaIcons, g as generatePwaImageType } from '../shared/nuxt.
|
|
6
|
+
import { p as pwaIcons, g as generatePwaImageType } from '../shared/nuxt.689bb9f6.mjs';
|
|
7
7
|
import '@nuxt/kit';
|
|
8
8
|
import 'vite-plugin-pwa';
|
|
9
9
|
import 'node:crypto';
|
package/dist/module.d.mts
CHANGED
|
@@ -23,6 +23,44 @@ interface ClientOptions {
|
|
|
23
23
|
installPrompt?: boolean | string;
|
|
24
24
|
}
|
|
25
25
|
interface PwaModuleOptions extends Partial<VitePWAOptions> {
|
|
26
|
+
/**
|
|
27
|
+
* Experimental features.
|
|
28
|
+
*/
|
|
29
|
+
experimental?: {
|
|
30
|
+
/**
|
|
31
|
+
* NOTE: this option will be ignored if using the `injectManifest` strategy or when Nuxt experimental payload
|
|
32
|
+
* extraction is disabled.
|
|
33
|
+
*
|
|
34
|
+
* Enable custom runtime caching to resolve the payload.json requests with query parameters when offline:
|
|
35
|
+
* - Workbox doesn't allow to configure `precacheAndRoute` `urlManipulation` option when using the `generateSW` strategy.
|
|
36
|
+
* - Nuxt SSG will generate a payload.json file and will fetch it with a query parameter.
|
|
37
|
+
* - The service worker cannot resolve the payload.json request with query parameters, and you won't get the payload when offline.
|
|
38
|
+
*
|
|
39
|
+
* Enabling this option will add a custom runtime caching handler to the service worker to resolve the payload files
|
|
40
|
+
* with query parameters when offline: the runtime caching handler will redirect to the payload.json file without
|
|
41
|
+
* query parameters when the original request fails.
|
|
42
|
+
*
|
|
43
|
+
* If you're using `injectManifest` strategy, you can fix the issue in your custom service worker adding the
|
|
44
|
+
* following `urlManipulation` callback to the `precacheAndRouter` call:
|
|
45
|
+
* ```ts
|
|
46
|
+
* // self.__WB_MANIFEST is the default injection point
|
|
47
|
+
* precacheAndRoute(
|
|
48
|
+
* self.__WB_MANIFEST,
|
|
49
|
+
* {
|
|
50
|
+
* urlManipulation: ({ url }) => {
|
|
51
|
+
* const urls: URL[] = []
|
|
52
|
+
* if (url.pathname.endsWith('_payload.json')) {
|
|
53
|
+
* const newUrl = new URL(url.href)
|
|
54
|
+
* newUrl.search = ''
|
|
55
|
+
* urls.push(newUrl)
|
|
56
|
+
* }
|
|
57
|
+
* return urls
|
|
58
|
+
* }
|
|
59
|
+
* }
|
|
60
|
+
* )
|
|
61
|
+
*/
|
|
62
|
+
enableWorkboxPayloadQueryParams?: true;
|
|
63
|
+
};
|
|
26
64
|
registerWebManifestInRouteRules?: boolean;
|
|
27
65
|
/**
|
|
28
66
|
* Writes the plugin to disk: defaults to false (debug).
|
package/dist/module.d.ts
CHANGED
|
@@ -23,6 +23,44 @@ interface ClientOptions {
|
|
|
23
23
|
installPrompt?: boolean | string;
|
|
24
24
|
}
|
|
25
25
|
interface PwaModuleOptions extends Partial<VitePWAOptions> {
|
|
26
|
+
/**
|
|
27
|
+
* Experimental features.
|
|
28
|
+
*/
|
|
29
|
+
experimental?: {
|
|
30
|
+
/**
|
|
31
|
+
* NOTE: this option will be ignored if using the `injectManifest` strategy or when Nuxt experimental payload
|
|
32
|
+
* extraction is disabled.
|
|
33
|
+
*
|
|
34
|
+
* Enable custom runtime caching to resolve the payload.json requests with query parameters when offline:
|
|
35
|
+
* - Workbox doesn't allow to configure `precacheAndRoute` `urlManipulation` option when using the `generateSW` strategy.
|
|
36
|
+
* - Nuxt SSG will generate a payload.json file and will fetch it with a query parameter.
|
|
37
|
+
* - The service worker cannot resolve the payload.json request with query parameters, and you won't get the payload when offline.
|
|
38
|
+
*
|
|
39
|
+
* Enabling this option will add a custom runtime caching handler to the service worker to resolve the payload files
|
|
40
|
+
* with query parameters when offline: the runtime caching handler will redirect to the payload.json file without
|
|
41
|
+
* query parameters when the original request fails.
|
|
42
|
+
*
|
|
43
|
+
* If you're using `injectManifest` strategy, you can fix the issue in your custom service worker adding the
|
|
44
|
+
* following `urlManipulation` callback to the `precacheAndRouter` call:
|
|
45
|
+
* ```ts
|
|
46
|
+
* // self.__WB_MANIFEST is the default injection point
|
|
47
|
+
* precacheAndRoute(
|
|
48
|
+
* self.__WB_MANIFEST,
|
|
49
|
+
* {
|
|
50
|
+
* urlManipulation: ({ url }) => {
|
|
51
|
+
* const urls: URL[] = []
|
|
52
|
+
* if (url.pathname.endsWith('_payload.json')) {
|
|
53
|
+
* const newUrl = new URL(url.href)
|
|
54
|
+
* newUrl.search = ''
|
|
55
|
+
* urls.push(newUrl)
|
|
56
|
+
* }
|
|
57
|
+
* return urls
|
|
58
|
+
* }
|
|
59
|
+
* }
|
|
60
|
+
* )
|
|
61
|
+
*/
|
|
62
|
+
enableWorkboxPayloadQueryParams?: true;
|
|
63
|
+
};
|
|
26
64
|
registerWebManifestInRouteRules?: boolean;
|
|
27
65
|
/**
|
|
28
66
|
* Writes the plugin to disk: defaults to false (debug).
|
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -6,7 +6,7 @@ import { createHash } from 'node:crypto';
|
|
|
6
6
|
import { createReadStream } from 'node:fs';
|
|
7
7
|
import { resolve } from 'pathe';
|
|
8
8
|
|
|
9
|
-
const version = "0.
|
|
9
|
+
const version = "1.0.1";
|
|
10
10
|
|
|
11
11
|
function configurePWAOptions(nuxt3_8, options, nuxt, nitroConfig) {
|
|
12
12
|
if (!options.outDir) {
|
|
@@ -20,6 +20,7 @@ function configurePWAOptions(nuxt3_8, options, nuxt, nitroConfig) {
|
|
|
20
20
|
options.injectManifest = options.injectManifest ?? {};
|
|
21
21
|
config = options.injectManifest;
|
|
22
22
|
} else {
|
|
23
|
+
options.strategies = "generateSW";
|
|
23
24
|
options.workbox = options.workbox ?? {};
|
|
24
25
|
if (options.registerType === "autoUpdate" && (options.client?.registerPlugin || options.injectRegister === "script" || options.injectRegister === "inline")) {
|
|
25
26
|
options.workbox.clientsClaim = true;
|
|
@@ -46,6 +47,25 @@ function configurePWAOptions(nuxt3_8, options, nuxt, nitroConfig) {
|
|
|
46
47
|
if (enableGlobPatterns) {
|
|
47
48
|
config.globPatterns = config.globPatterns ?? [];
|
|
48
49
|
config.globPatterns.push("**/_payload.json");
|
|
50
|
+
if (options.strategies === "generateSW" && options.experimental?.enableWorkboxPayloadQueryParams) {
|
|
51
|
+
options.workbox.runtimeCaching = options.workbox.runtimeCaching ?? [];
|
|
52
|
+
options.workbox.runtimeCaching.push({
|
|
53
|
+
urlPattern: /\/_payload\.json\?/,
|
|
54
|
+
handler: "NetworkOnly",
|
|
55
|
+
options: {
|
|
56
|
+
plugins: [{
|
|
57
|
+
/* this callback will be called when the fetch call fails */
|
|
58
|
+
handlerDidError: async ({ request }) => {
|
|
59
|
+
const url = new URL(request.url);
|
|
60
|
+
url.search = "";
|
|
61
|
+
return Response.redirect(url.href, 302);
|
|
62
|
+
},
|
|
63
|
+
/* this callback will prevent caching the response */
|
|
64
|
+
cacheWillUpdate: async () => null
|
|
65
|
+
}]
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
}
|
|
49
69
|
}
|
|
50
70
|
}
|
|
51
71
|
let appManifestFolder;
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vite-pwa/nuxt",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
5
|
-
"packageManager": "pnpm@10.
|
|
4
|
+
"version": "1.0.1",
|
|
5
|
+
"packageManager": "pnpm@10.11.0",
|
|
6
6
|
"description": "Zero-config PWA for Nuxt 3",
|
|
7
7
|
"author": "antfu <anthonyfu117@hotmail.com>",
|
|
8
8
|
"license": "MIT",
|
|
@@ -61,7 +61,7 @@
|
|
|
61
61
|
"test:with-build": "nr dev:prepare && nr prepack && nr test"
|
|
62
62
|
},
|
|
63
63
|
"peerDependencies": {
|
|
64
|
-
"@vite-pwa/assets-generator": "^0.
|
|
64
|
+
"@vite-pwa/assets-generator": "^1.0.0"
|
|
65
65
|
},
|
|
66
66
|
"peerDependenciesMeta": {
|
|
67
67
|
"@vite-pwa/assets-generator": {
|
|
@@ -72,7 +72,7 @@
|
|
|
72
72
|
"@nuxt/kit": "^3.9.0",
|
|
73
73
|
"pathe": "^1.1.1",
|
|
74
74
|
"ufo": "^1.3.2",
|
|
75
|
-
"vite-plugin-pwa": "
|
|
75
|
+
"vite-plugin-pwa": "^1.0.0"
|
|
76
76
|
},
|
|
77
77
|
"devDependencies": {
|
|
78
78
|
"@antfu/eslint-config": "^4.11.0",
|
|
@@ -113,4 +113,4 @@
|
|
|
113
113
|
"stackblitz": {
|
|
114
114
|
"startCommand": "nr prepack && nr dev:prepare && nr dev"
|
|
115
115
|
}
|
|
116
|
-
}
|
|
116
|
+
}
|