@vite-pwa/vitepress 0.2.3 โ†’ 0.3.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.
package/README.md CHANGED
@@ -41,11 +41,13 @@ Zero-config PWA Plugin for VitePress
41
41
  - โœจ **Static assets handling**: configure static assets for offline support
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
- - ๐Ÿ’ฅ PWA Assets Generator: generate all the PWA assets from a single command and a single source image
44
+ - ๐Ÿ’ฅ **PWA Assets Generator**: generate all the PWA assets from a single command and a single source image
45
45
 
46
46
  ## ๐Ÿ“ฆ Install
47
47
 
48
- > Requires Vite 3.1.0+
48
+ > From v0.3, `@vite-pwa/vitepress` requires **Vite 5** and **VitePress 1.0.0-rc.26 or above**.
49
+
50
+ > Using any version older than v0.3 requires Vite 3.1.0+.
49
51
 
50
52
  ```bash
51
53
  npm i @vite-pwa/vitepress -D
@@ -59,7 +61,7 @@ pnpm add @vite-pwa/vitepress -D
59
61
 
60
62
  ## ๐Ÿฆ„ Usage
61
63
 
62
- You will need wrap your VitePress config with `withPwa`:
64
+ You will need to wrap your VitePress config with `withPwa`:
63
65
 
64
66
  ```ts
65
67
  // .vitepress/config.ts
package/dist/index.cjs CHANGED
@@ -2,18 +2,28 @@
2
2
 
3
3
  const vitePluginPwa = require('vite-plugin-pwa');
4
4
 
5
- function configurePWAOptions(options) {
6
- if (!options.outDir)
7
- options.outDir = ".vitepress/dist";
8
- if (options.strategies === "injectManifest") {
9
- options.injectManifest = options.injectManifest ?? {};
5
+ function escapeStringRegexp(value) {
6
+ return value.replace(/[|\\{}()[\]^$+*?.]/g, "\\$&").replace(/-/g, "\\x2d");
7
+ }
8
+
9
+ function configurePWAOptions(config) {
10
+ const pwa = config.pwa ?? {};
11
+ const assetsDir = config.assetsDir ? config.assetsDir.replace(/\\/g, "/").replace(/^\.?\/|\/$/g, "") : "assets";
12
+ const dontCacheBustURLsMatching = new RegExp(`^${escapeStringRegexp(assetsDir)}/`);
13
+ if (!pwa.outDir)
14
+ pwa.outDir = ".vitepress/dist";
15
+ if (pwa.strategies === "injectManifest") {
16
+ pwa.injectManifest = pwa.injectManifest ?? {};
17
+ pwa.injectManifest.dontCacheBustURLsMatching = dontCacheBustURLsMatching;
10
18
  } else {
11
- options.workbox = options.workbox ?? {};
12
- if (options.registerType === "autoUpdate" && (options.injectRegister === "script" || options.injectRegister === "inline")) {
13
- options.workbox.clientsClaim = true;
14
- options.workbox.skipWaiting = true;
19
+ pwa.workbox = pwa.workbox ?? {};
20
+ pwa.workbox.dontCacheBustURLsMatching = dontCacheBustURLsMatching;
21
+ if (pwa.registerType === "autoUpdate" && (pwa.injectRegister === "script" || pwa.injectRegister === "script-defer" || pwa.injectRegister === "inline")) {
22
+ pwa.workbox.clientsClaim = true;
23
+ pwa.workbox.skipWaiting = true;
15
24
  }
16
25
  }
26
+ return pwa;
17
27
  }
18
28
 
19
29
  function withUserConfig(config) {
@@ -32,8 +42,7 @@ function withUserConfig(config) {
32
42
  if (pwaPlugin)
33
43
  throw new Error("Remove vite-plugin-pwa plugin from Vite Plugins entry in VitePress config file");
34
44
  }
35
- const { pwa = {} } = config;
36
- configurePWAOptions(pwa);
45
+ const pwa = configurePWAOptions(config);
37
46
  let api;
38
47
  vitePlugins.push(
39
48
  vitePluginPwa.VitePWA({ ...pwa }),
@@ -62,20 +71,31 @@ function withUserConfig(config) {
62
71
  }
63
72
  const registerSWData = api?.registerSWData();
64
73
  if (registerSWData && registerSWData.shouldRegisterSW) {
65
- if (registerSWData.inline) {
74
+ if (registerSWData.mode === "inline") {
66
75
  head.push([
67
76
  "script",
68
77
  { id: "vite-plugin-pwa:inline-sw" },
69
78
  `if('serviceWorker' in navigator) {window.addEventListener('load', () => {navigator.serviceWorker.register('${registerSWData.inlinePath}', { scope: '${registerSWData.scope}' })})}`
70
79
  ]);
71
80
  } else {
72
- head.push([
73
- "script",
74
- {
75
- id: "vite-plugin-pwa:register-sw",
76
- src: registerSWData.registerPath
77
- }
78
- ]);
81
+ if (registerSWData.mode === "script-defer") {
82
+ head.push([
83
+ "script",
84
+ {
85
+ id: "vite-plugin-pwa:register-sw",
86
+ defer: "defer",
87
+ src: registerSWData.registerPath
88
+ }
89
+ ]);
90
+ } else {
91
+ head.push([
92
+ "script",
93
+ {
94
+ id: "vite-plugin-pwa:register-sw",
95
+ src: registerSWData.registerPath
96
+ }
97
+ ]);
98
+ }
79
99
  }
80
100
  }
81
101
  return head;
@@ -115,9 +135,6 @@ function withUserConfig(config) {
115
135
  };
116
136
  return vitePressConfig;
117
137
  }
118
- function escapeStringRegexp(value) {
119
- return value.replace(/[|\\{}()[\]^$+*?.]/g, "\\$&").replace(/-/g, "\\x2d");
120
- }
121
138
 
122
139
  async function withPwa(config) {
123
140
  if (typeof config === "function") {
package/dist/index.mjs CHANGED
@@ -1,17 +1,27 @@
1
1
  import { VitePWA } from 'vite-plugin-pwa';
2
2
 
3
- function configurePWAOptions(options) {
4
- if (!options.outDir)
5
- options.outDir = ".vitepress/dist";
6
- if (options.strategies === "injectManifest") {
7
- options.injectManifest = options.injectManifest ?? {};
3
+ function escapeStringRegexp(value) {
4
+ return value.replace(/[|\\{}()[\]^$+*?.]/g, "\\$&").replace(/-/g, "\\x2d");
5
+ }
6
+
7
+ function configurePWAOptions(config) {
8
+ const pwa = config.pwa ?? {};
9
+ const assetsDir = config.assetsDir ? config.assetsDir.replace(/\\/g, "/").replace(/^\.?\/|\/$/g, "") : "assets";
10
+ const dontCacheBustURLsMatching = new RegExp(`^${escapeStringRegexp(assetsDir)}/`);
11
+ if (!pwa.outDir)
12
+ pwa.outDir = ".vitepress/dist";
13
+ if (pwa.strategies === "injectManifest") {
14
+ pwa.injectManifest = pwa.injectManifest ?? {};
15
+ pwa.injectManifest.dontCacheBustURLsMatching = dontCacheBustURLsMatching;
8
16
  } else {
9
- options.workbox = options.workbox ?? {};
10
- if (options.registerType === "autoUpdate" && (options.injectRegister === "script" || options.injectRegister === "inline")) {
11
- options.workbox.clientsClaim = true;
12
- options.workbox.skipWaiting = true;
17
+ pwa.workbox = pwa.workbox ?? {};
18
+ pwa.workbox.dontCacheBustURLsMatching = dontCacheBustURLsMatching;
19
+ if (pwa.registerType === "autoUpdate" && (pwa.injectRegister === "script" || pwa.injectRegister === "script-defer" || pwa.injectRegister === "inline")) {
20
+ pwa.workbox.clientsClaim = true;
21
+ pwa.workbox.skipWaiting = true;
13
22
  }
14
23
  }
24
+ return pwa;
15
25
  }
16
26
 
17
27
  function withUserConfig(config) {
@@ -30,8 +40,7 @@ function withUserConfig(config) {
30
40
  if (pwaPlugin)
31
41
  throw new Error("Remove vite-plugin-pwa plugin from Vite Plugins entry in VitePress config file");
32
42
  }
33
- const { pwa = {} } = config;
34
- configurePWAOptions(pwa);
43
+ const pwa = configurePWAOptions(config);
35
44
  let api;
36
45
  vitePlugins.push(
37
46
  VitePWA({ ...pwa }),
@@ -60,20 +69,31 @@ function withUserConfig(config) {
60
69
  }
61
70
  const registerSWData = api?.registerSWData();
62
71
  if (registerSWData && registerSWData.shouldRegisterSW) {
63
- if (registerSWData.inline) {
72
+ if (registerSWData.mode === "inline") {
64
73
  head.push([
65
74
  "script",
66
75
  { id: "vite-plugin-pwa:inline-sw" },
67
76
  `if('serviceWorker' in navigator) {window.addEventListener('load', () => {navigator.serviceWorker.register('${registerSWData.inlinePath}', { scope: '${registerSWData.scope}' })})}`
68
77
  ]);
69
78
  } else {
70
- head.push([
71
- "script",
72
- {
73
- id: "vite-plugin-pwa:register-sw",
74
- src: registerSWData.registerPath
75
- }
76
- ]);
79
+ if (registerSWData.mode === "script-defer") {
80
+ head.push([
81
+ "script",
82
+ {
83
+ id: "vite-plugin-pwa:register-sw",
84
+ defer: "defer",
85
+ src: registerSWData.registerPath
86
+ }
87
+ ]);
88
+ } else {
89
+ head.push([
90
+ "script",
91
+ {
92
+ id: "vite-plugin-pwa:register-sw",
93
+ src: registerSWData.registerPath
94
+ }
95
+ ]);
96
+ }
77
97
  }
78
98
  }
79
99
  return head;
@@ -113,9 +133,6 @@ function withUserConfig(config) {
113
133
  };
114
134
  return vitePressConfig;
115
135
  }
116
- function escapeStringRegexp(value) {
117
- return value.replace(/[|\\{}()[\]^$+*?.]/g, "\\$&").replace(/-/g, "\\x2d");
118
- }
119
136
 
120
137
  async function withPwa(config) {
121
138
  if (typeof config === "function") {
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@vite-pwa/vitepress",
3
3
  "type": "module",
4
- "version": "0.2.3",
5
- "packageManager": "pnpm@8.9.0",
4
+ "version": "0.3.1",
5
+ "packageManager": "pnpm@8.11.0",
6
6
  "description": "Zero-config PWA for VitePress",
7
7
  "author": "antfu <anthonyfu117@hotmail.com>",
8
8
  "license": "MIT",
@@ -23,12 +23,11 @@
23
23
  "exports": {
24
24
  ".": {
25
25
  "types": "./dist/index.d.ts",
26
- "require": "./dist/index.cjs",
27
- "import": "./dist/index.mjs"
26
+ "default": "./dist/index.mjs"
28
27
  },
29
28
  "./dist/*": "./dist/*"
30
29
  },
31
- "main": "dist/index.cjs",
30
+ "main": "dist/index.mjs",
32
31
  "module": "dist/index.mjs",
33
32
  "types": "dist/index.d.ts",
34
33
  "files": [
@@ -43,21 +42,21 @@
43
42
  "release": "bumpp && npm publish"
44
43
  },
45
44
  "peerDependencies": {
46
- "vite-plugin-pwa": ">=0.16.5 <1"
45
+ "vite-plugin-pwa": ">=0.17.2 <1"
47
46
  },
48
47
  "devDependencies": {
49
- "@antfu/eslint-config": "^0.41.0",
50
- "@antfu/ni": "^0.21.8",
51
- "@types/debug": "^4.1.8",
52
- "@typescript-eslint/eslint-plugin": "^6.6.0",
48
+ "@antfu/eslint-config": "^0.43.1",
49
+ "@antfu/ni": "^0.21.9",
50
+ "@types/debug": "^4.1.12",
51
+ "@typescript-eslint/eslint-plugin": "^6.11.0",
53
52
  "bumpp": "^9.2.0",
54
- "eslint": "^8.49.0",
53
+ "eslint": "^8.54.0",
55
54
  "https-localhost": "^4.7.1",
56
55
  "typescript": "^5.2.2",
57
56
  "unbuild": "^2.0.0",
58
- "vite": "^4.4.9",
59
- "vite-plugin-pwa": ">=0.16.5 <1",
60
- "vitepress": "1.0.0-beta.3"
57
+ "vite": "^5.0.0",
58
+ "vite-plugin-pwa": ">=0.17.2 <1",
59
+ "vitepress": "1.0.0-rc.28"
61
60
  },
62
61
  "pnpm": {
63
62
  "peerDependencyRules": {
@@ -66,4 +65,4 @@
66
65
  ]
67
66
  }
68
67
  }
69
- }
68
+ }