@vite-pwa/nuxt 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.
@@ -0,0 +1,49 @@
1
+ import * as _nuxt_schema from '@nuxt/schema';
2
+ import { VitePWAOptions } from 'vite-plugin-pwa';
3
+
4
+ interface ClientOptions {
5
+ /**
6
+ * Exposes the plugin: defaults to true.
7
+ */
8
+ registerPlugin?: boolean;
9
+ /**
10
+ * Registers a periodic sync for updates interval: value in seconds.
11
+ */
12
+ periodicSyncForUpdates?: number;
13
+ /**
14
+ * Will prevent showing native PWA install prompt: defaults to false.
15
+ *
16
+ * When set to true or no empty string, the native PWA install prompt will be prevented.
17
+ *
18
+ * When set to a string, it will be used as the key in `localStorage` to prevent show the PWA install prompt widget.
19
+ *
20
+ * When set to true, the key used will be `vite-pwa:hide-install`.
21
+ */
22
+ installPrompt?: boolean | string;
23
+ }
24
+ interface PwaModuleOptions extends Partial<VitePWAOptions> {
25
+ registerWebManifestInRouteRules?: boolean;
26
+ /**
27
+ * Writes the plugin to disk: defaults to false (debug).
28
+ */
29
+ writePlugin?: boolean;
30
+ /**
31
+ * Options for plugin.
32
+ */
33
+ client?: ClientOptions;
34
+ }
35
+
36
+ declare const _default: _nuxt_schema.NuxtModule<PwaModuleOptions>;
37
+
38
+ interface ModuleOptions extends PwaModuleOptions {
39
+ }
40
+ declare module '@nuxt/schema' {
41
+ interface NuxtConfig {
42
+ ['vuetify']?: Partial<ModuleOptions>;
43
+ }
44
+ interface NuxtOptions {
45
+ ['vuetify']?: ModuleOptions;
46
+ }
47
+ }
48
+
49
+ export { type ClientOptions, type ModuleOptions, type PwaModuleOptions, _default as default };
package/dist/module.d.ts CHANGED
@@ -21,7 +21,7 @@ interface ClientOptions {
21
21
  */
22
22
  installPrompt?: boolean | string;
23
23
  }
24
- interface ModuleOptions extends Partial<VitePWAOptions> {
24
+ interface PwaModuleOptions extends Partial<VitePWAOptions> {
25
25
  registerWebManifestInRouteRules?: boolean;
26
26
  /**
27
27
  * Writes the plugin to disk: defaults to false (debug).
@@ -33,6 +33,17 @@ interface ModuleOptions extends Partial<VitePWAOptions> {
33
33
  client?: ClientOptions;
34
34
  }
35
35
 
36
- declare const _default: _nuxt_schema.NuxtModule<ModuleOptions>;
36
+ declare const _default: _nuxt_schema.NuxtModule<PwaModuleOptions>;
37
37
 
38
- export { ClientOptions, ModuleOptions, _default as default };
38
+ interface ModuleOptions extends PwaModuleOptions {
39
+ }
40
+ declare module '@nuxt/schema' {
41
+ interface NuxtConfig {
42
+ ['vuetify']?: Partial<ModuleOptions>;
43
+ }
44
+ interface NuxtOptions {
45
+ ['vuetify']?: ModuleOptions;
46
+ }
47
+ }
48
+
49
+ export { type ClientOptions, type ModuleOptions, type PwaModuleOptions, _default as default };
package/dist/module.json CHANGED
@@ -1,5 +1,9 @@
1
1
  {
2
2
  "name": "pwa",
3
3
  "configKey": "pwa",
4
- "version": "0.2.3"
4
+ "compatibility": {
5
+ "nuxt": "^3.6.5",
6
+ "bridge": false
7
+ },
8
+ "version": "0.3.1"
5
9
  }
package/dist/module.mjs CHANGED
@@ -1,10 +1,12 @@
1
1
  import { join } from 'node:path';
2
2
  import { writeFile, mkdir } from 'node:fs/promises';
3
- import { defineNuxtModule, createResolver, addPlugin, addComponent, extendWebpackConfig } from '@nuxt/kit';
3
+ import { defineNuxtModule, createResolver, getNuxtVersion, addPlugin, addComponent, extendWebpackConfig } from '@nuxt/kit';
4
4
  import { VitePWA } from 'vite-plugin-pwa';
5
5
  import { resolve } from 'pathe';
6
6
 
7
- function configurePWAOptions(options, nuxt, nitroConfig) {
7
+ const version = "0.3.1";
8
+
9
+ function configurePWAOptions(nuxt3_8, options, nuxt, nitroConfig) {
8
10
  if (!options.outDir) {
9
11
  const publicDir = nitroConfig.output?.publicDir ?? nuxt.options.nitro?.output?.publicDir;
10
12
  options.outDir = publicDir ? resolve(publicDir) : resolve(nuxt.options.buildDir, "../.output/public");
@@ -30,10 +32,25 @@ function configurePWAOptions(options, nuxt, nitroConfig) {
30
32
  options.workbox.navigateFallback = nuxt.options.app.baseURL ?? "/";
31
33
  config = options.workbox;
32
34
  }
35
+ if (nuxt.options.experimental.payloadExtraction) {
36
+ config.globPatterns = config.globPatterns ?? [];
37
+ config.globPatterns.push("**/_payload.json");
38
+ }
39
+ let appManifestFolder;
40
+ if (nuxt3_8 && nuxt.options.experimental.appManifest) {
41
+ config.globPatterns = config.globPatterns ?? [];
42
+ appManifestFolder = nuxt.options.app.buildAssetsDir ?? "_nuxt/";
43
+ if (appManifestFolder[0] === "/")
44
+ appManifestFolder = appManifestFolder.slice(1);
45
+ if (appManifestFolder[appManifestFolder.length - 1] !== "/")
46
+ appManifestFolder += "/";
47
+ appManifestFolder += "builds/";
48
+ config.globPatterns.push(`${appManifestFolder}**/*.json`);
49
+ }
33
50
  if (!nuxt.options.dev && !config.manifestTransforms)
34
- config.manifestTransforms = [createManifestTransform(nuxt.options.app.baseURL ?? "/")];
51
+ config.manifestTransforms = [createManifestTransform(nuxt.options.app.baseURL ?? "/", appManifestFolder)];
35
52
  }
36
- function createManifestTransform(base) {
53
+ function createManifestTransform(base, appManifestFolder) {
37
54
  return async (entries) => {
38
55
  entries.filter((e) => e && e.url.endsWith(".html")).forEach((e) => {
39
56
  const url = e.url.startsWith("/") ? e.url.slice(1) : e.url;
@@ -45,11 +62,17 @@ function createManifestTransform(base) {
45
62
  e.url = parts.length > 1 ? parts.slice(0, parts.length - 1).join("/") : parts[0];
46
63
  }
47
64
  });
65
+ if (appManifestFolder) {
66
+ const regExp = /(\/)?[0-9a-f]{8}\b-[0-9a-f]{4}\b-[0-9a-f]{4}\b-[0-9a-f]{4}\b-[0-9a-f]{12}\.json$/i;
67
+ entries.filter((e) => e && e.url.startsWith(appManifestFolder) && regExp.test(e.url)).forEach((e) => {
68
+ e.revision = null;
69
+ });
70
+ }
48
71
  return { manifest: entries, warnings: [] };
49
72
  };
50
73
  }
51
74
 
52
- async function regeneratePWA(dir, api) {
75
+ async function regeneratePWA(_dir, api) {
53
76
  if (!api || api.disabled)
54
77
  return;
55
78
  await api.generateSW();
@@ -63,7 +86,12 @@ async function writeWebManifest(dir, path, api) {
63
86
  const module = defineNuxtModule({
64
87
  meta: {
65
88
  name: "pwa",
66
- configKey: "pwa"
89
+ configKey: "pwa",
90
+ compatibility: {
91
+ nuxt: "^3.6.5",
92
+ bridge: false
93
+ },
94
+ version
67
95
  },
68
96
  defaults: (nuxt) => ({
69
97
  base: nuxt.options.app.baseURL,
@@ -80,6 +108,8 @@ const module = defineNuxtModule({
80
108
  }),
81
109
  async setup(options, nuxt) {
82
110
  const resolver = createResolver(import.meta.url);
111
+ const nuxtVersion = getNuxtVersion(nuxt).split(".").map((v) => Number.parseInt(v));
112
+ const nuxt3_8 = nuxtVersion.length > 1 && (nuxtVersion[0] > 3 || nuxtVersion[0] === 3 && nuxtVersion[1] >= 8);
83
113
  let vitePwaClientPlugin;
84
114
  const resolveVitePluginPWAAPI = () => {
85
115
  return vitePwaClientPlugin?.api;
@@ -99,11 +129,19 @@ const module = defineNuxtModule({
99
129
  mode: "client"
100
130
  });
101
131
  }
102
- await addComponent({
103
- name: "VitePwaManifest",
104
- filePath: resolver.resolve(runtimeDir, "components/VitePwaManifest")
105
- });
132
+ await Promise.all([
133
+ addComponent({
134
+ name: "VitePwaManifest",
135
+ filePath: resolver.resolve(runtimeDir, "components/VitePwaManifest")
136
+ }),
137
+ addComponent({
138
+ name: "NuxtPwaManifest",
139
+ filePath: resolver.resolve(runtimeDir, "components/VitePwaManifest")
140
+ })
141
+ ]);
106
142
  nuxt.hook("prepare:types", ({ references }) => {
143
+ const types = resolver.resolve(runtimeDir, "plugins/types");
144
+ references.push({ path: resolver.resolve(nuxt.options.buildDir, types) });
107
145
  references.push({ types: "@vite-pwa/nuxt/configuration" });
108
146
  references.push({ types: "vite-plugin-pwa/vue" });
109
147
  references.push({ types: "vite-plugin-pwa/info" });
@@ -115,7 +153,7 @@ const module = defineNuxtModule({
115
153
  maxAge: 0
116
154
  });
117
155
  nuxt.hook("nitro:init", (nitro) => {
118
- configurePWAOptions(options, nuxt, nitro.options);
156
+ configurePWAOptions(nuxt3_8, options, nuxt, nitro.options);
119
157
  });
120
158
  nuxt.hook("vite:extend", ({ config }) => {
121
159
  const plugin = config.plugins?.find((p) => p && typeof p === "object" && "name" in p && p.name === "vite-plugin-pwa");
@@ -222,21 +260,30 @@ export const periodicSyncForUpdates = ${typeof client.periodicSyncForUpdates ===
222
260
  }
223
261
  });
224
262
  }
225
- nuxt.hook("nitro:init", (nitro) => {
226
- nitro.hooks.hook("rollup:before", async () => {
263
+ if (nuxt3_8) {
264
+ nuxt.hook("nitro:build:public-assets", async () => {
227
265
  await regeneratePWA(
228
266
  options.outDir,
229
267
  resolveVitePluginPWAAPI()
230
268
  );
231
269
  });
232
- });
233
- if (nuxt.options._generate) {
234
- nuxt.hook("close", async () => {
235
- await regeneratePWA(
236
- options.outDir,
237
- resolveVitePluginPWAAPI()
238
- );
270
+ } else {
271
+ nuxt.hook("nitro:init", (nitro) => {
272
+ nitro.hooks.hook("rollup:before", async () => {
273
+ await regeneratePWA(
274
+ options.outDir,
275
+ resolveVitePluginPWAAPI()
276
+ );
277
+ });
239
278
  });
279
+ if (nuxt.options._generate) {
280
+ nuxt.hook("close", async () => {
281
+ await regeneratePWA(
282
+ options.outDir,
283
+ resolveVitePluginPWAAPI()
284
+ );
285
+ });
286
+ }
240
287
  }
241
288
  }
242
289
  }
@@ -1,6 +1,6 @@
1
1
  import type { UnwrapNestedRefs } from 'vue';
2
- import type { PwaInjection } from './pwa';
3
- import type { Plugin } from '#app/nuxt';
2
+ import type { PwaInjection } from './types';
3
+ import type { Plugin } from '#app';
4
4
  declare const plugin: Plugin<{
5
5
  pwa?: UnwrapNestedRefs<PwaInjection>;
6
6
  }>;
@@ -1,6 +1,6 @@
1
1
  import type { UnwrapNestedRefs } from 'vue';
2
- import type { PwaInjection } from './pwa';
3
- import type { Plugin } from '#app/nuxt';
2
+ import type { PwaInjection } from './types';
3
+ import type { Plugin } from '#app';
4
4
  declare const plugin: Plugin<{
5
5
  pwa?: UnwrapNestedRefs<PwaInjection>;
6
6
  }>;
@@ -0,0 +1,30 @@
1
+ import type { Ref } from 'vue'
2
+ import type { UnwrapNestedRefs } from 'vue'
3
+
4
+ export interface PwaInjection {
5
+ isInstalled: boolean
6
+ showInstallPrompt: Ref<boolean>
7
+ cancelInstall: () => void
8
+ install: () => Promise<void>
9
+ swActivated: Ref<boolean>
10
+ registrationError: Ref<boolean>
11
+ offlineReady: Ref<boolean>
12
+ needRefresh: Ref<boolean>
13
+ updateServiceWorker: (reloadPage?: boolean | undefined) => Promise<void>
14
+ cancelPrompt: () => Promise<void>
15
+ getSWRegistration: () => ServiceWorkerRegistration | undefined
16
+ }
17
+
18
+ declare module '#app' {
19
+ interface NuxtApp {
20
+ $pwa?: UnwrapNestedRefs<PwaInjection>
21
+ }
22
+ }
23
+
24
+ declare module '@vue/runtime-core' {
25
+ interface ComponentCustomProperties {
26
+ $pwa?: UnwrapNestedRefs<PwaInjection>
27
+ }
28
+ }
29
+
30
+ export {}
@@ -0,0 +1,16 @@
1
+
2
+ import type { ModuleOptions } from './module'
3
+
4
+
5
+ declare module '@nuxt/schema' {
6
+ interface NuxtConfig { ['pwa']?: Partial<ModuleOptions> }
7
+ interface NuxtOptions { ['pwa']?: ModuleOptions }
8
+ }
9
+
10
+ declare module 'nuxt/schema' {
11
+ interface NuxtConfig { ['pwa']?: Partial<ModuleOptions> }
12
+ interface NuxtOptions { ['pwa']?: ModuleOptions }
13
+ }
14
+
15
+
16
+ export type { ClientOptions, ModuleOptions, PwaModuleOptions, default } from './module'
package/dist/types.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
 
2
- import { ModuleOptions } from './module'
2
+ import type { ModuleOptions } from './module'
3
+
3
4
 
4
5
  declare module '@nuxt/schema' {
5
6
  interface NuxtConfig { ['pwa']?: Partial<ModuleOptions> }
@@ -12,4 +13,4 @@ declare module 'nuxt/schema' {
12
13
  }
13
14
 
14
15
 
15
- export { ClientOptions, ModuleOptions, default } from './module'
16
+ export type { ClientOptions, ModuleOptions, PwaModuleOptions, default } from './module'
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@vite-pwa/nuxt",
3
3
  "type": "module",
4
- "version": "0.2.3",
5
- "packageManager": "pnpm@8.10.3",
4
+ "version": "0.3.1",
5
+ "packageManager": "pnpm@8.10.5",
6
6
  "description": "Zero-config PWA for Nuxt 3",
7
7
  "author": "antfu <anthonyfu117@hotmail.com>",
8
8
  "license": "MIT",
@@ -22,13 +22,13 @@
22
22
  ],
23
23
  "exports": {
24
24
  ".": {
25
- "types": "./dist/types.d.ts",
26
- "import": "./dist/module.mjs",
27
- "require": "./dist/module.cjs"
25
+ "types": "./dist/types.d.mts",
26
+ "default": "./dist/module.mjs"
28
27
  },
29
28
  "./configuration": {
30
29
  "types": "./configuration.d.ts"
31
- }
30
+ },
31
+ "./*": "./*"
32
32
  },
33
33
  "main": "./dist/module.cjs",
34
34
  "types": "./dist/types.d.ts",
@@ -37,7 +37,7 @@
37
37
  "*.d.ts"
38
38
  ],
39
39
  "scripts": {
40
- "prepack": "nuxt-module-build prepare && nuxt-module-build",
40
+ "prepack": "nuxt-module-build prepare && nuxt-module-build build",
41
41
  "dev": "nuxi dev playground",
42
42
  "dev:generate": "nuxi generate playground",
43
43
  "dev:generate:netlify": "NITRO_PRESET=netlify nuxi generate playground",
@@ -56,31 +56,30 @@
56
56
  "test": "nr test:build && nr test:generate",
57
57
  "test:with-build": "nr dev:prepare && nr prepack && nr test"
58
58
  },
59
- "peerDependencies": {
60
- "@nuxt/kit": "^3.6.2",
61
- "vite-plugin-pwa": ">=0.16.5 <1"
62
- },
63
59
  "dependencies": {
64
- "@nuxt/kit": "^3.6.2",
60
+ "@nuxt/kit": "^3.8.2",
65
61
  "pathe": "^1.1.1",
66
- "ufo": "^1.3.1",
67
- "vite-plugin-pwa": ">=0.16.5 <1"
62
+ "ufo": "^1.3.2",
63
+ "vite-plugin-pwa": ">=0.16.7 <1"
68
64
  },
69
65
  "devDependencies": {
70
- "@antfu/eslint-config": "^0.41.0",
71
- "@antfu/ni": "^0.21.8",
72
- "@nuxt/module-builder": "^0.4.0",
73
- "@nuxt/schema": "^3.6.5",
74
- "@nuxt/test-utils": "^3.5.3",
66
+ "@antfu/eslint-config": "^0.43.1",
67
+ "@antfu/ni": "^0.21.10",
68
+ "@nuxt/module-builder": "^0.5.4",
69
+ "@nuxt/schema": "^3.8.2",
70
+ "@nuxt/test-utils": "^3.8.1",
75
71
  "@playwright/test": "^1.37.1",
76
72
  "@types/node": "^18",
77
73
  "bumpp": "^9.2.0",
78
- "eslint": "^8.49.0",
74
+ "eslint": "^8.54.0",
79
75
  "node-fetch-native": "^1.4.1",
80
- "nuxt": "^3.6.5",
76
+ "nuxt": "^3.8.2",
77
+ "publint": "^0.2.5",
78
+ "rimraf": "^5.0.5",
81
79
  "serve": "^14.2.1",
82
- "typescript": "^5.2.2",
83
- "vitest": "^0.34.4"
80
+ "typescript": "^5.3.2",
81
+ "vitest": "^0.34.4",
82
+ "vue-tsc": "^1.8.22"
84
83
  },
85
84
  "build": {
86
85
  "externals": [
@@ -95,4 +94,4 @@
95
94
  "vite-plugin-pwa"
96
95
  ]
97
96
  }
98
- }
97
+ }
@@ -1,14 +0,0 @@
1
- import type { Ref } from 'vue';
2
- export interface PwaInjection {
3
- isInstalled: boolean;
4
- showInstallPrompt: Ref<boolean>;
5
- cancelInstall: () => void;
6
- install: () => Promise<void>;
7
- swActivated: Ref<boolean>;
8
- registrationError: Ref<boolean>;
9
- offlineReady: Ref<boolean>;
10
- needRefresh: Ref<boolean>;
11
- updateServiceWorker: (reloadPage?: boolean | undefined) => Promise<void>;
12
- cancelPrompt: () => Promise<void>;
13
- getSWRegistration: () => ServiceWorkerRegistration | undefined;
14
- }
File without changes