@vite-pwa/vitepress 0.2.1 → 0.2.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/dist/index.cjs +32 -1
- package/dist/index.d.cts +10 -0
- package/dist/index.d.mts +10 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.mjs +32 -1
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -80,9 +80,40 @@ function withUserConfig(config) {
|
|
|
80
80
|
}
|
|
81
81
|
return head;
|
|
82
82
|
};
|
|
83
|
+
let allowlist;
|
|
84
|
+
if (pwa.strategies !== "injectManifest" && pwa.experimental?.includeAllowlist === true) {
|
|
85
|
+
pwa.workbox = pwa.workbox ?? {};
|
|
86
|
+
allowlist = pwa.workbox.navigateFallbackAllowlist = pwa.workbox.navigateFallbackAllowlist ?? [];
|
|
87
|
+
pwa.workbox.runtimeCaching = pwa.workbox.runtimeCaching ?? [];
|
|
88
|
+
pwa.workbox.runtimeCaching.push({
|
|
89
|
+
urlPattern: ({ request, sameOrigin }) => {
|
|
90
|
+
return sameOrigin && request.mode === "navigate";
|
|
91
|
+
},
|
|
92
|
+
handler: "NetworkOnly",
|
|
93
|
+
options: {
|
|
94
|
+
plugins: [{
|
|
95
|
+
/* this callback will be called when the fetch call fails */
|
|
96
|
+
handlerDidError: async () => Response.redirect("404", 302),
|
|
97
|
+
/* this callback will prevent caching the response */
|
|
98
|
+
cacheWillUpdate: async () => null
|
|
99
|
+
}]
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
}
|
|
83
103
|
vitePressConfig.buildEnd = async (siteConfig) => {
|
|
84
104
|
await userBuildEnd?.(siteConfig);
|
|
85
|
-
api && !api.disabled
|
|
105
|
+
if (api && !api.disabled) {
|
|
106
|
+
if (typeof allowlist !== "undefined") {
|
|
107
|
+
const base = siteConfig.site.base ?? "/";
|
|
108
|
+
for (const page of siteConfig.pages) {
|
|
109
|
+
if (page === "index.md")
|
|
110
|
+
allowlist.push(new RegExp(`^${base}(.html)?$`));
|
|
111
|
+
else
|
|
112
|
+
allowlist.push(new RegExp(`^${base}${page.replace(/\.md$/, "(.html)?")}$`));
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
await api.generateSW();
|
|
116
|
+
}
|
|
86
117
|
};
|
|
87
118
|
return vitePressConfig;
|
|
88
119
|
}
|
package/dist/index.d.cts
CHANGED
|
@@ -4,6 +4,16 @@ import { DefaultTheme, UserConfigExport } from 'vitepress';
|
|
|
4
4
|
import { VitePWAOptions } from 'vite-plugin-pwa';
|
|
5
5
|
|
|
6
6
|
interface PwaOptions extends Partial<VitePWAOptions> {
|
|
7
|
+
experimental?: {
|
|
8
|
+
/**
|
|
9
|
+
* When using `generateSW` strategy, include the logic to handle the `workbox.navigateFallbackAllowlist` option.
|
|
10
|
+
*
|
|
11
|
+
* @see https://github.com/vite-pwa/vitepress/issues/22
|
|
12
|
+
*
|
|
13
|
+
* @default false
|
|
14
|
+
*/
|
|
15
|
+
includeAllowlist?: boolean;
|
|
16
|
+
};
|
|
7
17
|
}
|
|
8
18
|
declare module 'vitepress' {
|
|
9
19
|
interface UserConfig {
|
package/dist/index.d.mts
CHANGED
|
@@ -4,6 +4,16 @@ import { DefaultTheme, UserConfigExport } from 'vitepress';
|
|
|
4
4
|
import { VitePWAOptions } from 'vite-plugin-pwa';
|
|
5
5
|
|
|
6
6
|
interface PwaOptions extends Partial<VitePWAOptions> {
|
|
7
|
+
experimental?: {
|
|
8
|
+
/**
|
|
9
|
+
* When using `generateSW` strategy, include the logic to handle the `workbox.navigateFallbackAllowlist` option.
|
|
10
|
+
*
|
|
11
|
+
* @see https://github.com/vite-pwa/vitepress/issues/22
|
|
12
|
+
*
|
|
13
|
+
* @default false
|
|
14
|
+
*/
|
|
15
|
+
includeAllowlist?: boolean;
|
|
16
|
+
};
|
|
7
17
|
}
|
|
8
18
|
declare module 'vitepress' {
|
|
9
19
|
interface UserConfig {
|
package/dist/index.d.ts
CHANGED
|
@@ -4,6 +4,16 @@ import { DefaultTheme, UserConfigExport } from 'vitepress';
|
|
|
4
4
|
import { VitePWAOptions } from 'vite-plugin-pwa';
|
|
5
5
|
|
|
6
6
|
interface PwaOptions extends Partial<VitePWAOptions> {
|
|
7
|
+
experimental?: {
|
|
8
|
+
/**
|
|
9
|
+
* When using `generateSW` strategy, include the logic to handle the `workbox.navigateFallbackAllowlist` option.
|
|
10
|
+
*
|
|
11
|
+
* @see https://github.com/vite-pwa/vitepress/issues/22
|
|
12
|
+
*
|
|
13
|
+
* @default false
|
|
14
|
+
*/
|
|
15
|
+
includeAllowlist?: boolean;
|
|
16
|
+
};
|
|
7
17
|
}
|
|
8
18
|
declare module 'vitepress' {
|
|
9
19
|
interface UserConfig {
|
package/dist/index.mjs
CHANGED
|
@@ -78,9 +78,40 @@ function withUserConfig(config) {
|
|
|
78
78
|
}
|
|
79
79
|
return head;
|
|
80
80
|
};
|
|
81
|
+
let allowlist;
|
|
82
|
+
if (pwa.strategies !== "injectManifest" && pwa.experimental?.includeAllowlist === true) {
|
|
83
|
+
pwa.workbox = pwa.workbox ?? {};
|
|
84
|
+
allowlist = pwa.workbox.navigateFallbackAllowlist = pwa.workbox.navigateFallbackAllowlist ?? [];
|
|
85
|
+
pwa.workbox.runtimeCaching = pwa.workbox.runtimeCaching ?? [];
|
|
86
|
+
pwa.workbox.runtimeCaching.push({
|
|
87
|
+
urlPattern: ({ request, sameOrigin }) => {
|
|
88
|
+
return sameOrigin && request.mode === "navigate";
|
|
89
|
+
},
|
|
90
|
+
handler: "NetworkOnly",
|
|
91
|
+
options: {
|
|
92
|
+
plugins: [{
|
|
93
|
+
/* this callback will be called when the fetch call fails */
|
|
94
|
+
handlerDidError: async () => Response.redirect("404", 302),
|
|
95
|
+
/* this callback will prevent caching the response */
|
|
96
|
+
cacheWillUpdate: async () => null
|
|
97
|
+
}]
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
}
|
|
81
101
|
vitePressConfig.buildEnd = async (siteConfig) => {
|
|
82
102
|
await userBuildEnd?.(siteConfig);
|
|
83
|
-
api && !api.disabled
|
|
103
|
+
if (api && !api.disabled) {
|
|
104
|
+
if (typeof allowlist !== "undefined") {
|
|
105
|
+
const base = siteConfig.site.base ?? "/";
|
|
106
|
+
for (const page of siteConfig.pages) {
|
|
107
|
+
if (page === "index.md")
|
|
108
|
+
allowlist.push(new RegExp(`^${base}(.html)?$`));
|
|
109
|
+
else
|
|
110
|
+
allowlist.push(new RegExp(`^${base}${page.replace(/\.md$/, "(.html)?")}$`));
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
await api.generateSW();
|
|
114
|
+
}
|
|
84
115
|
};
|
|
85
116
|
return vitePressConfig;
|
|
86
117
|
}
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vite-pwa/vitepress",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.2.
|
|
5
|
-
"packageManager": "pnpm@8.
|
|
4
|
+
"version": "0.2.2",
|
|
5
|
+
"packageManager": "pnpm@8.9.0",
|
|
6
6
|
"description": "Zero-config PWA for VitePress",
|
|
7
7
|
"author": "antfu <anthonyfu117@hotmail.com>",
|
|
8
8
|
"license": "MIT",
|
|
@@ -66,4 +66,4 @@
|
|
|
66
66
|
]
|
|
67
67
|
}
|
|
68
68
|
}
|
|
69
|
-
}
|
|
69
|
+
}
|