@vite-pwa/vitepress 0.1.0 → 0.2.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/dist/index.cjs CHANGED
@@ -1,6 +1,5 @@
1
1
  'use strict';
2
2
 
3
- const vitepress = require('vitepress');
4
3
  const vitePluginPwa = require('vite-plugin-pwa');
5
4
 
6
5
  function configurePWAOptions(options) {
@@ -17,7 +16,7 @@ function configurePWAOptions(options) {
17
16
  }
18
17
  }
19
18
 
20
- function withPwa(config) {
19
+ function withUserConfig(config) {
21
20
  let viteConf = config.vite;
22
21
  if (!viteConf) {
23
22
  viteConf = {};
@@ -33,7 +32,7 @@ function withPwa(config) {
33
32
  if (pwaPlugin)
34
33
  throw new Error("Remove vite-plugin-pwa plugin from Vite Plugins entry in VitePress config file");
35
34
  }
36
- const { pwa = {}, ...vitePressOptions } = config;
35
+ const { pwa = {} } = config;
37
36
  configurePWAOptions(pwa);
38
37
  let api;
39
38
  vitePlugins.push(
@@ -48,7 +47,7 @@ function withPwa(config) {
48
47
  }
49
48
  }
50
49
  );
51
- const vitePressConfig = vitepress.defineConfigWithTheme(vitePressOptions);
50
+ const vitePressConfig = config;
52
51
  const userTransformHead = vitePressConfig.transformHead;
53
52
  const userBuildEnd = vitePressConfig.buildEnd;
54
53
  vitePressConfig.transformHead = async (ctx) => {
@@ -88,4 +87,14 @@ function withPwa(config) {
88
87
  return vitePressConfig;
89
88
  }
90
89
 
90
+ async function withPwa(config) {
91
+ if (typeof config === "function") {
92
+ return async (ctx) => {
93
+ const userConfig = await config(ctx);
94
+ return withUserConfig(userConfig);
95
+ };
96
+ }
97
+ return withUserConfig(await config);
98
+ }
99
+
91
100
  exports.withPwa = withPwa;
package/dist/index.d.ts CHANGED
@@ -1,4 +1,6 @@
1
- import { UserConfig } from 'vitepress';
1
+ import * as vite from 'vite';
2
+ import * as vitepress_dist_node from 'vitepress/dist/node';
3
+ import { DefaultTheme, UserConfigExport } from 'vitepress';
2
4
  import { VitePWAOptions } from 'vite-plugin-pwa';
3
5
 
4
6
  interface PwaOptions extends Partial<VitePWAOptions> {
@@ -9,6 +11,6 @@ declare module 'vitepress' {
9
11
  }
10
12
  }
11
13
 
12
- declare function withPwa(config: UserConfig): UserConfig<any>;
14
+ declare function withPwa<T = DefaultTheme.Config>(config: UserConfigExport<T>): Promise<vitepress_dist_node.UserConfig<T> | ((ctx: vite.ConfigEnv) => Promise<vitepress_dist_node.UserConfig<T>>)>;
13
15
 
14
16
  export { PwaOptions, withPwa };
package/dist/index.mjs CHANGED
@@ -1,4 +1,3 @@
1
- import { defineConfigWithTheme } from 'vitepress';
2
1
  import { VitePWA } from 'vite-plugin-pwa';
3
2
 
4
3
  function configurePWAOptions(options) {
@@ -15,7 +14,7 @@ function configurePWAOptions(options) {
15
14
  }
16
15
  }
17
16
 
18
- function withPwa(config) {
17
+ function withUserConfig(config) {
19
18
  let viteConf = config.vite;
20
19
  if (!viteConf) {
21
20
  viteConf = {};
@@ -31,7 +30,7 @@ function withPwa(config) {
31
30
  if (pwaPlugin)
32
31
  throw new Error("Remove vite-plugin-pwa plugin from Vite Plugins entry in VitePress config file");
33
32
  }
34
- const { pwa = {}, ...vitePressOptions } = config;
33
+ const { pwa = {} } = config;
35
34
  configurePWAOptions(pwa);
36
35
  let api;
37
36
  vitePlugins.push(
@@ -46,7 +45,7 @@ function withPwa(config) {
46
45
  }
47
46
  }
48
47
  );
49
- const vitePressConfig = defineConfigWithTheme(vitePressOptions);
48
+ const vitePressConfig = config;
50
49
  const userTransformHead = vitePressConfig.transformHead;
51
50
  const userBuildEnd = vitePressConfig.buildEnd;
52
51
  vitePressConfig.transformHead = async (ctx) => {
@@ -86,4 +85,14 @@ function withPwa(config) {
86
85
  return vitePressConfig;
87
86
  }
88
87
 
88
+ async function withPwa(config) {
89
+ if (typeof config === "function") {
90
+ return async (ctx) => {
91
+ const userConfig = await config(ctx);
92
+ return withUserConfig(userConfig);
93
+ };
94
+ }
95
+ return withUserConfig(await config);
96
+ }
97
+
89
98
  export { withPwa };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vite-pwa/vitepress",
3
3
  "type": "module",
4
- "version": "0.1.0",
4
+ "version": "0.2.0",
5
5
  "packageManager": "pnpm@8.6.1",
6
6
  "description": "Zero-config PWA for VitePress",
7
7
  "author": "antfu <anthonyfu117@hotmail.com>",
@@ -57,7 +57,7 @@
57
57
  "unbuild": "^1.2.1",
58
58
  "vite": "^4.3.9",
59
59
  "vite-plugin-pwa": ">=0.16.3 <1",
60
- "vitepress": "1.0.0-beta.1"
60
+ "vitepress": "1.0.0-beta.2"
61
61
  },
62
62
  "pnpm": {
63
63
  "peerDependencyRules": {
@@ -66,4 +66,4 @@
66
66
  ]
67
67
  }
68
68
  }
69
- }
69
+ }