@vite-pwa/vitepress 0.2.2 โ†’ 0.3.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 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 === "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 }),
@@ -106,10 +115,8 @@ function withUserConfig(config) {
106
115
  if (typeof allowlist !== "undefined") {
107
116
  const base = siteConfig.site.base ?? "/";
108
117
  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)?")}$`));
118
+ const regex = page === "index.md" ? escapeStringRegexp(base) : escapeStringRegexp(`${base}${page.replace(/\.md$/, "")}`);
119
+ allowlist.push(new RegExp(`^${regex}(\\.html)?$`));
113
120
  }
114
121
  }
115
122
  await api.generateSW();
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 === "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 }),
@@ -104,10 +113,8 @@ function withUserConfig(config) {
104
113
  if (typeof allowlist !== "undefined") {
105
114
  const base = siteConfig.site.base ?? "/";
106
115
  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)?")}$`));
116
+ const regex = page === "index.md" ? escapeStringRegexp(base) : escapeStringRegexp(`${base}${page.replace(/\.md$/, "")}`);
117
+ allowlist.push(new RegExp(`^${regex}(\\.html)?$`));
111
118
  }
112
119
  }
113
120
  await api.generateSW();
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@vite-pwa/vitepress",
3
3
  "type": "module",
4
- "version": "0.2.2",
5
- "packageManager": "pnpm@8.9.0",
4
+ "version": "0.3.0",
5
+ "packageManager": "pnpm@8.10.5",
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.0 <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.0 <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
+ }