@vite-pwa/nuxt 1.0.0 → 1.0.3
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/dist/chunks/pwa-icons.mjs +1 -1
- package/dist/module.d.mts +46 -2
- package/dist/module.d.ts +46 -2
- package/dist/module.json +1 -1
- package/dist/module.mjs +1 -1
- package/dist/shared/{nuxt.4b59a78c.mjs → nuxt.73bdad2b.mjs} +33 -1
- package/dist/types.d.mts +10 -2
- package/dist/types.d.ts +10 -2
- package/package.json +3 -3
|
@@ -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.73bdad2b.mjs';
|
|
7
7
|
import '@nuxt/kit';
|
|
8
8
|
import 'vite-plugin-pwa';
|
|
9
9
|
import 'node:crypto';
|
package/dist/module.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as _nuxt_schema from '@nuxt/schema';
|
|
2
2
|
import { HookResult } from '@nuxt/schema';
|
|
3
|
-
import { VitePWAOptions } from 'vite-plugin-pwa';
|
|
3
|
+
import { VitePWAOptions, ResolvedVitePWAOptions } from 'vite-plugin-pwa';
|
|
4
4
|
|
|
5
5
|
interface ClientOptions {
|
|
6
6
|
/**
|
|
@@ -23,6 +23,45 @@ 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
|
+
*/
|
|
63
|
+
enableWorkboxPayloadQueryParams?: true;
|
|
64
|
+
};
|
|
26
65
|
registerWebManifestInRouteRules?: boolean;
|
|
27
66
|
/**
|
|
28
67
|
* Writes the plugin to disk: defaults to false (debug).
|
|
@@ -33,9 +72,14 @@ interface PwaModuleOptions extends Partial<VitePWAOptions> {
|
|
|
33
72
|
*/
|
|
34
73
|
client?: ClientOptions;
|
|
35
74
|
}
|
|
75
|
+
interface PwaModuleHooks {
|
|
76
|
+
'pwa:beforeBuildServiceWorker': (options: ResolvedVitePWAOptions) => HookResult;
|
|
77
|
+
}
|
|
36
78
|
|
|
37
79
|
interface ModuleOptions extends PwaModuleOptions {
|
|
38
80
|
}
|
|
81
|
+
interface ModuleHooks extends PwaModuleHooks {
|
|
82
|
+
}
|
|
39
83
|
interface ModuleRuntimeHooks {
|
|
40
84
|
/**
|
|
41
85
|
* Emitted when the service worker is registered
|
|
@@ -63,4 +107,4 @@ interface ModuleRuntimeHooks {
|
|
|
63
107
|
}
|
|
64
108
|
declare const _default: _nuxt_schema.NuxtModule<ModuleOptions>;
|
|
65
109
|
|
|
66
|
-
export { type ClientOptions, type ModuleOptions, type ModuleRuntimeHooks, type PwaModuleOptions, _default as default };
|
|
110
|
+
export { type ClientOptions, type ModuleHooks, type ModuleOptions, type ModuleRuntimeHooks, type PwaModuleHooks, type PwaModuleOptions, _default as default };
|
package/dist/module.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as _nuxt_schema from '@nuxt/schema';
|
|
2
2
|
import { HookResult } from '@nuxt/schema';
|
|
3
|
-
import { VitePWAOptions } from 'vite-plugin-pwa';
|
|
3
|
+
import { VitePWAOptions, ResolvedVitePWAOptions } from 'vite-plugin-pwa';
|
|
4
4
|
|
|
5
5
|
interface ClientOptions {
|
|
6
6
|
/**
|
|
@@ -23,6 +23,45 @@ 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
|
+
*/
|
|
63
|
+
enableWorkboxPayloadQueryParams?: true;
|
|
64
|
+
};
|
|
26
65
|
registerWebManifestInRouteRules?: boolean;
|
|
27
66
|
/**
|
|
28
67
|
* Writes the plugin to disk: defaults to false (debug).
|
|
@@ -33,9 +72,14 @@ interface PwaModuleOptions extends Partial<VitePWAOptions> {
|
|
|
33
72
|
*/
|
|
34
73
|
client?: ClientOptions;
|
|
35
74
|
}
|
|
75
|
+
interface PwaModuleHooks {
|
|
76
|
+
'pwa:beforeBuildServiceWorker': (options: ResolvedVitePWAOptions) => HookResult;
|
|
77
|
+
}
|
|
36
78
|
|
|
37
79
|
interface ModuleOptions extends PwaModuleOptions {
|
|
38
80
|
}
|
|
81
|
+
interface ModuleHooks extends PwaModuleHooks {
|
|
82
|
+
}
|
|
39
83
|
interface ModuleRuntimeHooks {
|
|
40
84
|
/**
|
|
41
85
|
* Emitted when the service worker is registered
|
|
@@ -63,4 +107,4 @@ interface ModuleRuntimeHooks {
|
|
|
63
107
|
}
|
|
64
108
|
declare const _default: _nuxt_schema.NuxtModule<ModuleOptions>;
|
|
65
109
|
|
|
66
|
-
export { type ClientOptions, type ModuleOptions, type ModuleRuntimeHooks, type PwaModuleOptions, _default as default };
|
|
110
|
+
export { type ClientOptions, type ModuleHooks, type ModuleOptions, type ModuleRuntimeHooks, type PwaModuleHooks, type PwaModuleOptions, _default as default };
|
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 = "1.0.
|
|
9
|
+
const version = "1.0.3";
|
|
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;
|
|
@@ -63,6 +83,18 @@ function configurePWAOptions(nuxt3_8, options, nuxt, nitroConfig) {
|
|
|
63
83
|
outDir: options.outDir
|
|
64
84
|
};
|
|
65
85
|
}
|
|
86
|
+
const integration = options.integration ?? {};
|
|
87
|
+
const {
|
|
88
|
+
beforeBuildServiceWorker: original,
|
|
89
|
+
...rest
|
|
90
|
+
} = integration;
|
|
91
|
+
options.integration = {
|
|
92
|
+
...rest,
|
|
93
|
+
async beforeBuildServiceWorker(resolvedPwaOptions) {
|
|
94
|
+
await original?.(resolvedPwaOptions);
|
|
95
|
+
await nuxt.callHook("pwa:beforeBuildServiceWorker", resolvedPwaOptions);
|
|
96
|
+
}
|
|
97
|
+
};
|
|
66
98
|
}
|
|
67
99
|
function createManifestTransform(base, publicFolder, appManifestFolder) {
|
|
68
100
|
return async (entries) => {
|
package/dist/types.d.mts
CHANGED
|
@@ -1,7 +1,15 @@
|
|
|
1
|
-
import type { ModuleRuntimeHooks } from './module.js'
|
|
1
|
+
import type { ModuleHooks, ModuleRuntimeHooks } from './module.js'
|
|
2
2
|
|
|
3
3
|
declare module '#app' {
|
|
4
4
|
interface RuntimeNuxtHooks extends ModuleRuntimeHooks {}
|
|
5
5
|
}
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
declare module '@nuxt/schema' {
|
|
8
|
+
interface NuxtHooks extends ModuleHooks {}
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
declare module 'nuxt/schema' {
|
|
12
|
+
interface NuxtHooks extends ModuleHooks {}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export { type ClientOptions, type ModuleHooks, type ModuleOptions, type ModuleRuntimeHooks, type PwaModuleHooks, type PwaModuleOptions, default } from './module.js'
|
package/dist/types.d.ts
CHANGED
|
@@ -1,7 +1,15 @@
|
|
|
1
|
-
import type { ModuleRuntimeHooks } from './module'
|
|
1
|
+
import type { ModuleHooks, ModuleRuntimeHooks } from './module'
|
|
2
2
|
|
|
3
3
|
declare module '#app' {
|
|
4
4
|
interface RuntimeNuxtHooks extends ModuleRuntimeHooks {}
|
|
5
5
|
}
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
declare module '@nuxt/schema' {
|
|
8
|
+
interface NuxtHooks extends ModuleHooks {}
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
declare module 'nuxt/schema' {
|
|
12
|
+
interface NuxtHooks extends ModuleHooks {}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export { type ClientOptions, type ModuleHooks, type ModuleOptions, type ModuleRuntimeHooks, type PwaModuleHooks, type PwaModuleOptions, default } from './module'
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vite-pwa/nuxt",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.0.
|
|
5
|
-
"packageManager": "pnpm@10.
|
|
4
|
+
"version": "1.0.3",
|
|
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",
|
|
@@ -113,4 +113,4 @@
|
|
|
113
113
|
"stackblitz": {
|
|
114
114
|
"startCommand": "nr prepack && nr dev:prepare && nr dev"
|
|
115
115
|
}
|
|
116
|
-
}
|
|
116
|
+
}
|