@vite-pwa/vitepress 0.3.0 โ 0.4.0
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/README.md +2 -1
- package/dist/index.cjs +60 -20
- package/dist/index.d.cts +1 -2
- package/dist/index.d.mts +1 -2
- package/dist/index.d.ts +1 -2
- package/dist/index.mjs +60 -20
- package/package.json +12 -6
package/README.md
CHANGED
|
@@ -42,10 +42,11 @@ Zero-config PWA Plugin for VitePress
|
|
|
42
42
|
- ๐ **Development Support**: debug your custom service worker logic as you develop your application
|
|
43
43
|
- ๐ ๏ธ **Versatile**: integration with meta frameworks: [รฎles](https://github.com/ElMassimo/iles), [SvelteKit](https://github.com/sveltejs/kit), [VitePress](https://github.com/vuejs/vitepress), [Astro](https://github.com/withastro/astro), and [Nuxt 3](https://github.com/nuxt/nuxt)
|
|
44
44
|
- ๐ฅ **PWA Assets Generator**: generate all the PWA assets from a single command and a single source image
|
|
45
|
+
- ๐ **PWA Assets Integration**: serving, generating and injecting PWA Assets on the fly in your application
|
|
45
46
|
|
|
46
47
|
## ๐ฆ Install
|
|
47
48
|
|
|
48
|
-
> From v0.3
|
|
49
|
+
> From v0.3, `@vite-pwa/vitepress` requires **Vite 5** and **VitePress 1.0.0-rc.26 or above**.
|
|
49
50
|
|
|
50
51
|
> Using any version older than v0.3 requires Vite 3.1.0+.
|
|
51
52
|
|
package/dist/index.cjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const vitePluginPwa = require('vite-plugin-pwa');
|
|
4
|
+
const node_path = require('node:path');
|
|
4
5
|
|
|
5
6
|
function escapeStringRegexp(value) {
|
|
6
7
|
return value.replace(/[|\\{}()[\]^$+*?.]/g, "\\$&").replace(/-/g, "\\x2d");
|
|
@@ -12,13 +13,21 @@ function configurePWAOptions(config) {
|
|
|
12
13
|
const dontCacheBustURLsMatching = new RegExp(`^${escapeStringRegexp(assetsDir)}/`);
|
|
13
14
|
if (!pwa.outDir)
|
|
14
15
|
pwa.outDir = ".vitepress/dist";
|
|
16
|
+
if (pwa.pwaAssets) {
|
|
17
|
+
const publicDir = typeof config.vite?.publicDir === "string" ? node_path.resolve(config.vite.publicDir) : node_path.resolve("public");
|
|
18
|
+
pwa.pwaAssets.integration = {
|
|
19
|
+
baseUrl: config.base ?? config.vite?.base ?? "/",
|
|
20
|
+
publicDir,
|
|
21
|
+
outDir: node_path.resolve(pwa.outDir)
|
|
22
|
+
};
|
|
23
|
+
}
|
|
15
24
|
if (pwa.strategies === "injectManifest") {
|
|
16
25
|
pwa.injectManifest = pwa.injectManifest ?? {};
|
|
17
26
|
pwa.injectManifest.dontCacheBustURLsMatching = dontCacheBustURLsMatching;
|
|
18
27
|
} else {
|
|
19
28
|
pwa.workbox = pwa.workbox ?? {};
|
|
20
29
|
pwa.workbox.dontCacheBustURLsMatching = dontCacheBustURLsMatching;
|
|
21
|
-
if (pwa.registerType === "autoUpdate" && (pwa.injectRegister === "script" || pwa.injectRegister === "inline")) {
|
|
30
|
+
if (pwa.registerType === "autoUpdate" && (pwa.injectRegister === "script" || pwa.injectRegister === "script-defer" || pwa.injectRegister === "inline")) {
|
|
22
31
|
pwa.workbox.clientsClaim = true;
|
|
23
32
|
pwa.workbox.skipWaiting = true;
|
|
24
33
|
}
|
|
@@ -44,23 +53,43 @@ function withUserConfig(config) {
|
|
|
44
53
|
}
|
|
45
54
|
const pwa = configurePWAOptions(config);
|
|
46
55
|
let api;
|
|
47
|
-
vitePlugins.push(
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
56
|
+
vitePlugins.push(vitePluginPwa.VitePWA({ ...pwa }));
|
|
57
|
+
vitePlugins.push({
|
|
58
|
+
name: "vite-plugin-pwa:pwa-assets:vitepress",
|
|
59
|
+
apply: "serve",
|
|
60
|
+
enforce: "pre",
|
|
61
|
+
configResolved(resolvedViteConfig) {
|
|
62
|
+
if (!resolvedViteConfig.build.ssr)
|
|
63
|
+
api = resolvedViteConfig.plugins.find((p) => p.name === "vite-plugin-pwa")?.api;
|
|
64
|
+
},
|
|
65
|
+
async handleHotUpdate({ file, server }) {
|
|
66
|
+
const pwaAssetsGenerator = await api?.pwaAssetsGenerator();
|
|
67
|
+
if (await pwaAssetsGenerator?.checkHotUpdate(file))
|
|
68
|
+
await server.restart();
|
|
57
69
|
}
|
|
58
|
-
);
|
|
70
|
+
});
|
|
71
|
+
vitePlugins.push({
|
|
72
|
+
name: "vite-plugin-pwa:vitepress",
|
|
73
|
+
apply: "build",
|
|
74
|
+
enforce: "post",
|
|
75
|
+
configResolved(resolvedViteConfig) {
|
|
76
|
+
if (!resolvedViteConfig.build.ssr)
|
|
77
|
+
api = resolvedViteConfig.plugins.find((p) => p.name === "vite-plugin-pwa")?.api;
|
|
78
|
+
}
|
|
79
|
+
});
|
|
59
80
|
const vitePressConfig = config;
|
|
60
81
|
const userTransformHead = vitePressConfig.transformHead;
|
|
61
82
|
const userBuildEnd = vitePressConfig.buildEnd;
|
|
62
83
|
vitePressConfig.transformHead = async (ctx) => {
|
|
63
84
|
const head = await userTransformHead?.(ctx) ?? [];
|
|
85
|
+
const assetsGenerator = await api?.pwaAssetsGenerator();
|
|
86
|
+
if (assetsGenerator) {
|
|
87
|
+
const htmlAssets = assetsGenerator.resolveHtmlAssets();
|
|
88
|
+
if (htmlAssets.themeColor)
|
|
89
|
+
head.push(["meta", { name: "theme-color", content: htmlAssets.themeColor.content }]);
|
|
90
|
+
for (const link of htmlAssets.links)
|
|
91
|
+
head.push(["link", { ...link }]);
|
|
92
|
+
}
|
|
64
93
|
const webManifestData = api?.webManifestData();
|
|
65
94
|
if (webManifestData) {
|
|
66
95
|
const href = webManifestData.href;
|
|
@@ -71,20 +100,31 @@ function withUserConfig(config) {
|
|
|
71
100
|
}
|
|
72
101
|
const registerSWData = api?.registerSWData();
|
|
73
102
|
if (registerSWData && registerSWData.shouldRegisterSW) {
|
|
74
|
-
if (registerSWData.inline) {
|
|
103
|
+
if (registerSWData.mode === "inline") {
|
|
75
104
|
head.push([
|
|
76
105
|
"script",
|
|
77
106
|
{ id: "vite-plugin-pwa:inline-sw" },
|
|
78
107
|
`if('serviceWorker' in navigator) {window.addEventListener('load', () => {navigator.serviceWorker.register('${registerSWData.inlinePath}', { scope: '${registerSWData.scope}' })})}`
|
|
79
108
|
]);
|
|
80
109
|
} else {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
110
|
+
if (registerSWData.mode === "script-defer") {
|
|
111
|
+
head.push([
|
|
112
|
+
"script",
|
|
113
|
+
{
|
|
114
|
+
id: "vite-plugin-pwa:register-sw",
|
|
115
|
+
defer: "defer",
|
|
116
|
+
src: registerSWData.registerPath
|
|
117
|
+
}
|
|
118
|
+
]);
|
|
119
|
+
} else {
|
|
120
|
+
head.push([
|
|
121
|
+
"script",
|
|
122
|
+
{
|
|
123
|
+
id: "vite-plugin-pwa:register-sw",
|
|
124
|
+
src: registerSWData.registerPath
|
|
125
|
+
}
|
|
126
|
+
]);
|
|
127
|
+
}
|
|
88
128
|
}
|
|
89
129
|
}
|
|
90
130
|
return head;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import * as vite from 'vite';
|
|
2
1
|
import * as vitepress_dist_node from 'vitepress/dist/node';
|
|
3
2
|
import { DefaultTheme, UserConfigExport } from 'vitepress';
|
|
4
3
|
import { VitePWAOptions } from 'vite-plugin-pwa';
|
|
@@ -21,6 +20,6 @@ declare module 'vitepress' {
|
|
|
21
20
|
}
|
|
22
21
|
}
|
|
23
22
|
|
|
24
|
-
declare function withPwa<T = DefaultTheme.Config>(config: UserConfigExport<T>): Promise<vitepress_dist_node.UserConfig<T> |
|
|
23
|
+
declare function withPwa<T = DefaultTheme.Config>(config: UserConfigExport<T>): Promise<vitepress_dist_node.UserConfig<T> | vitepress_dist_node.UserConfigFn<T>>;
|
|
25
24
|
|
|
26
25
|
export { type PwaOptions, withPwa };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import * as vite from 'vite';
|
|
2
1
|
import * as vitepress_dist_node from 'vitepress/dist/node';
|
|
3
2
|
import { DefaultTheme, UserConfigExport } from 'vitepress';
|
|
4
3
|
import { VitePWAOptions } from 'vite-plugin-pwa';
|
|
@@ -21,6 +20,6 @@ declare module 'vitepress' {
|
|
|
21
20
|
}
|
|
22
21
|
}
|
|
23
22
|
|
|
24
|
-
declare function withPwa<T = DefaultTheme.Config>(config: UserConfigExport<T>): Promise<vitepress_dist_node.UserConfig<T> |
|
|
23
|
+
declare function withPwa<T = DefaultTheme.Config>(config: UserConfigExport<T>): Promise<vitepress_dist_node.UserConfig<T> | vitepress_dist_node.UserConfigFn<T>>;
|
|
25
24
|
|
|
26
25
|
export { type PwaOptions, withPwa };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import * as vite from 'vite';
|
|
2
1
|
import * as vitepress_dist_node from 'vitepress/dist/node';
|
|
3
2
|
import { DefaultTheme, UserConfigExport } from 'vitepress';
|
|
4
3
|
import { VitePWAOptions } from 'vite-plugin-pwa';
|
|
@@ -21,6 +20,6 @@ declare module 'vitepress' {
|
|
|
21
20
|
}
|
|
22
21
|
}
|
|
23
22
|
|
|
24
|
-
declare function withPwa<T = DefaultTheme.Config>(config: UserConfigExport<T>): Promise<vitepress_dist_node.UserConfig<T> |
|
|
23
|
+
declare function withPwa<T = DefaultTheme.Config>(config: UserConfigExport<T>): Promise<vitepress_dist_node.UserConfig<T> | vitepress_dist_node.UserConfigFn<T>>;
|
|
25
24
|
|
|
26
25
|
export { type PwaOptions, withPwa };
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { VitePWA } from 'vite-plugin-pwa';
|
|
2
|
+
import { resolve } from 'node:path';
|
|
2
3
|
|
|
3
4
|
function escapeStringRegexp(value) {
|
|
4
5
|
return value.replace(/[|\\{}()[\]^$+*?.]/g, "\\$&").replace(/-/g, "\\x2d");
|
|
@@ -10,13 +11,21 @@ function configurePWAOptions(config) {
|
|
|
10
11
|
const dontCacheBustURLsMatching = new RegExp(`^${escapeStringRegexp(assetsDir)}/`);
|
|
11
12
|
if (!pwa.outDir)
|
|
12
13
|
pwa.outDir = ".vitepress/dist";
|
|
14
|
+
if (pwa.pwaAssets) {
|
|
15
|
+
const publicDir = typeof config.vite?.publicDir === "string" ? resolve(config.vite.publicDir) : resolve("public");
|
|
16
|
+
pwa.pwaAssets.integration = {
|
|
17
|
+
baseUrl: config.base ?? config.vite?.base ?? "/",
|
|
18
|
+
publicDir,
|
|
19
|
+
outDir: resolve(pwa.outDir)
|
|
20
|
+
};
|
|
21
|
+
}
|
|
13
22
|
if (pwa.strategies === "injectManifest") {
|
|
14
23
|
pwa.injectManifest = pwa.injectManifest ?? {};
|
|
15
24
|
pwa.injectManifest.dontCacheBustURLsMatching = dontCacheBustURLsMatching;
|
|
16
25
|
} else {
|
|
17
26
|
pwa.workbox = pwa.workbox ?? {};
|
|
18
27
|
pwa.workbox.dontCacheBustURLsMatching = dontCacheBustURLsMatching;
|
|
19
|
-
if (pwa.registerType === "autoUpdate" && (pwa.injectRegister === "script" || pwa.injectRegister === "inline")) {
|
|
28
|
+
if (pwa.registerType === "autoUpdate" && (pwa.injectRegister === "script" || pwa.injectRegister === "script-defer" || pwa.injectRegister === "inline")) {
|
|
20
29
|
pwa.workbox.clientsClaim = true;
|
|
21
30
|
pwa.workbox.skipWaiting = true;
|
|
22
31
|
}
|
|
@@ -42,23 +51,43 @@ function withUserConfig(config) {
|
|
|
42
51
|
}
|
|
43
52
|
const pwa = configurePWAOptions(config);
|
|
44
53
|
let api;
|
|
45
|
-
vitePlugins.push(
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
54
|
+
vitePlugins.push(VitePWA({ ...pwa }));
|
|
55
|
+
vitePlugins.push({
|
|
56
|
+
name: "vite-plugin-pwa:pwa-assets:vitepress",
|
|
57
|
+
apply: "serve",
|
|
58
|
+
enforce: "pre",
|
|
59
|
+
configResolved(resolvedViteConfig) {
|
|
60
|
+
if (!resolvedViteConfig.build.ssr)
|
|
61
|
+
api = resolvedViteConfig.plugins.find((p) => p.name === "vite-plugin-pwa")?.api;
|
|
62
|
+
},
|
|
63
|
+
async handleHotUpdate({ file, server }) {
|
|
64
|
+
const pwaAssetsGenerator = await api?.pwaAssetsGenerator();
|
|
65
|
+
if (await pwaAssetsGenerator?.checkHotUpdate(file))
|
|
66
|
+
await server.restart();
|
|
55
67
|
}
|
|
56
|
-
);
|
|
68
|
+
});
|
|
69
|
+
vitePlugins.push({
|
|
70
|
+
name: "vite-plugin-pwa:vitepress",
|
|
71
|
+
apply: "build",
|
|
72
|
+
enforce: "post",
|
|
73
|
+
configResolved(resolvedViteConfig) {
|
|
74
|
+
if (!resolvedViteConfig.build.ssr)
|
|
75
|
+
api = resolvedViteConfig.plugins.find((p) => p.name === "vite-plugin-pwa")?.api;
|
|
76
|
+
}
|
|
77
|
+
});
|
|
57
78
|
const vitePressConfig = config;
|
|
58
79
|
const userTransformHead = vitePressConfig.transformHead;
|
|
59
80
|
const userBuildEnd = vitePressConfig.buildEnd;
|
|
60
81
|
vitePressConfig.transformHead = async (ctx) => {
|
|
61
82
|
const head = await userTransformHead?.(ctx) ?? [];
|
|
83
|
+
const assetsGenerator = await api?.pwaAssetsGenerator();
|
|
84
|
+
if (assetsGenerator) {
|
|
85
|
+
const htmlAssets = assetsGenerator.resolveHtmlAssets();
|
|
86
|
+
if (htmlAssets.themeColor)
|
|
87
|
+
head.push(["meta", { name: "theme-color", content: htmlAssets.themeColor.content }]);
|
|
88
|
+
for (const link of htmlAssets.links)
|
|
89
|
+
head.push(["link", { ...link }]);
|
|
90
|
+
}
|
|
62
91
|
const webManifestData = api?.webManifestData();
|
|
63
92
|
if (webManifestData) {
|
|
64
93
|
const href = webManifestData.href;
|
|
@@ -69,20 +98,31 @@ function withUserConfig(config) {
|
|
|
69
98
|
}
|
|
70
99
|
const registerSWData = api?.registerSWData();
|
|
71
100
|
if (registerSWData && registerSWData.shouldRegisterSW) {
|
|
72
|
-
if (registerSWData.inline) {
|
|
101
|
+
if (registerSWData.mode === "inline") {
|
|
73
102
|
head.push([
|
|
74
103
|
"script",
|
|
75
104
|
{ id: "vite-plugin-pwa:inline-sw" },
|
|
76
105
|
`if('serviceWorker' in navigator) {window.addEventListener('load', () => {navigator.serviceWorker.register('${registerSWData.inlinePath}', { scope: '${registerSWData.scope}' })})}`
|
|
77
106
|
]);
|
|
78
107
|
} else {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
108
|
+
if (registerSWData.mode === "script-defer") {
|
|
109
|
+
head.push([
|
|
110
|
+
"script",
|
|
111
|
+
{
|
|
112
|
+
id: "vite-plugin-pwa:register-sw",
|
|
113
|
+
defer: "defer",
|
|
114
|
+
src: registerSWData.registerPath
|
|
115
|
+
}
|
|
116
|
+
]);
|
|
117
|
+
} else {
|
|
118
|
+
head.push([
|
|
119
|
+
"script",
|
|
120
|
+
{
|
|
121
|
+
id: "vite-plugin-pwa:register-sw",
|
|
122
|
+
src: registerSWData.registerPath
|
|
123
|
+
}
|
|
124
|
+
]);
|
|
125
|
+
}
|
|
86
126
|
}
|
|
87
127
|
}
|
|
88
128
|
return head;
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vite-pwa/vitepress",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
5
|
-
"packageManager": "pnpm@8.
|
|
4
|
+
"version": "0.4.0",
|
|
5
|
+
"packageManager": "pnpm@8.15.3",
|
|
6
6
|
"description": "Zero-config PWA for VitePress",
|
|
7
7
|
"author": "antfu <anthonyfu117@hotmail.com>",
|
|
8
8
|
"license": "MIT",
|
|
@@ -42,7 +42,13 @@
|
|
|
42
42
|
"release": "bumpp && npm publish"
|
|
43
43
|
},
|
|
44
44
|
"peerDependencies": {
|
|
45
|
-
"vite-
|
|
45
|
+
"@vite-pwa/assets-generator": "^0.2.4",
|
|
46
|
+
"vite-plugin-pwa": ">=0.19.0 <1"
|
|
47
|
+
},
|
|
48
|
+
"peerDependenciesMeta": {
|
|
49
|
+
"@vite-pwa/assets-generator": {
|
|
50
|
+
"optional": true
|
|
51
|
+
}
|
|
46
52
|
},
|
|
47
53
|
"devDependencies": {
|
|
48
54
|
"@antfu/eslint-config": "^0.43.1",
|
|
@@ -52,11 +58,11 @@
|
|
|
52
58
|
"bumpp": "^9.2.0",
|
|
53
59
|
"eslint": "^8.54.0",
|
|
54
60
|
"https-localhost": "^4.7.1",
|
|
55
|
-
"typescript": "^5.
|
|
61
|
+
"typescript": "^5.3.3",
|
|
56
62
|
"unbuild": "^2.0.0",
|
|
57
63
|
"vite": "^5.0.0",
|
|
58
|
-
"vite-plugin-pwa": ">=0.
|
|
59
|
-
"vitepress": "1.0.0-rc.
|
|
64
|
+
"vite-plugin-pwa": ">=0.19.0 <1",
|
|
65
|
+
"vitepress": "1.0.0-rc.42"
|
|
60
66
|
},
|
|
61
67
|
"pnpm": {
|
|
62
68
|
"peerDependencyRules": {
|