@vite-pwa/nuxt 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/dist/module.d.mts +49 -0
- package/dist/module.d.ts +14 -3
- package/dist/module.json +5 -1
- package/dist/module.mjs +44 -18
- package/dist/runtime/plugins/pwa.client.d.ts +2 -2
- package/dist/runtime/plugins/pwa.client.stub.d.ts +2 -2
- package/dist/runtime/plugins/types.d.ts +30 -0
- package/dist/types.d.mts +16 -0
- package/dist/types.d.ts +3 -2
- package/package.json +23 -24
- package/dist/runtime/plugins/pwa.d.ts +0 -14
- package/dist/runtime/plugins/pwa.mjs +0 -0
|
@@ -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
|
|
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<
|
|
36
|
+
declare const _default: _nuxt_schema.NuxtModule<PwaModuleOptions>;
|
|
37
37
|
|
|
38
|
-
|
|
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
package/dist/module.mjs
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
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, addPlugin, addComponent, extendWebpackConfig, getNuxtVersion } from '@nuxt/kit';
|
|
4
4
|
import { VitePWA } from 'vite-plugin-pwa';
|
|
5
5
|
import { resolve } from 'pathe';
|
|
6
6
|
|
|
7
|
+
const version = "0.3.0";
|
|
8
|
+
|
|
7
9
|
function configurePWAOptions(options, nuxt, nitroConfig) {
|
|
8
10
|
if (!options.outDir) {
|
|
9
11
|
const publicDir = nitroConfig.output?.publicDir ?? nuxt.options.nitro?.output?.publicDir;
|
|
@@ -26,11 +28,11 @@ function configurePWAOptions(options, nuxt, nitroConfig) {
|
|
|
26
28
|
if (options.devOptions?.enabled && !options.devOptions.navigateFallbackAllowlist)
|
|
27
29
|
options.devOptions.navigateFallbackAllowlist = [nuxt.options.app.baseURL ? new RegExp(nuxt.options.app.baseURL) : /\//];
|
|
28
30
|
}
|
|
29
|
-
if (!options.workbox
|
|
31
|
+
if (!("navigateFallback" in options.workbox))
|
|
30
32
|
options.workbox.navigateFallback = nuxt.options.app.baseURL ?? "/";
|
|
31
33
|
config = options.workbox;
|
|
32
34
|
}
|
|
33
|
-
if (!nuxt.options.dev)
|
|
35
|
+
if (!nuxt.options.dev && !config.manifestTransforms)
|
|
34
36
|
config.manifestTransforms = [createManifestTransform(nuxt.options.app.baseURL ?? "/")];
|
|
35
37
|
}
|
|
36
38
|
function createManifestTransform(base) {
|
|
@@ -49,7 +51,7 @@ function createManifestTransform(base) {
|
|
|
49
51
|
};
|
|
50
52
|
}
|
|
51
53
|
|
|
52
|
-
async function regeneratePWA(
|
|
54
|
+
async function regeneratePWA(_dir, api) {
|
|
53
55
|
if (!api || api.disabled)
|
|
54
56
|
return;
|
|
55
57
|
await api.generateSW();
|
|
@@ -63,7 +65,12 @@ async function writeWebManifest(dir, path, api) {
|
|
|
63
65
|
const module = defineNuxtModule({
|
|
64
66
|
meta: {
|
|
65
67
|
name: "pwa",
|
|
66
|
-
configKey: "pwa"
|
|
68
|
+
configKey: "pwa",
|
|
69
|
+
compatibility: {
|
|
70
|
+
nuxt: "^3.6.5",
|
|
71
|
+
bridge: false
|
|
72
|
+
},
|
|
73
|
+
version
|
|
67
74
|
},
|
|
68
75
|
defaults: (nuxt) => ({
|
|
69
76
|
base: nuxt.options.app.baseURL,
|
|
@@ -99,11 +106,19 @@ const module = defineNuxtModule({
|
|
|
99
106
|
mode: "client"
|
|
100
107
|
});
|
|
101
108
|
}
|
|
102
|
-
await
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
109
|
+
await Promise.all([
|
|
110
|
+
addComponent({
|
|
111
|
+
name: "VitePwaManifest",
|
|
112
|
+
filePath: resolver.resolve(runtimeDir, "components/VitePwaManifest")
|
|
113
|
+
}),
|
|
114
|
+
addComponent({
|
|
115
|
+
name: "NuxtPwaManifest",
|
|
116
|
+
filePath: resolver.resolve(runtimeDir, "components/VitePwaManifest")
|
|
117
|
+
})
|
|
118
|
+
]);
|
|
106
119
|
nuxt.hook("prepare:types", ({ references }) => {
|
|
120
|
+
const types = resolver.resolve(runtimeDir, "plugins/types");
|
|
121
|
+
references.push({ path: resolver.resolve(nuxt.options.buildDir, types) });
|
|
107
122
|
references.push({ types: "@vite-pwa/nuxt/configuration" });
|
|
108
123
|
references.push({ types: "vite-plugin-pwa/vue" });
|
|
109
124
|
references.push({ types: "vite-plugin-pwa/info" });
|
|
@@ -222,21 +237,32 @@ export const periodicSyncForUpdates = ${typeof client.periodicSyncForUpdates ===
|
|
|
222
237
|
}
|
|
223
238
|
});
|
|
224
239
|
}
|
|
225
|
-
nuxt.
|
|
226
|
-
|
|
240
|
+
const nuxtVersion = getNuxtVersion(nuxt).split(".").map((v) => Number.parseInt(v));
|
|
241
|
+
const nuxt3_8 = nuxtVersion.length > 1 && (nuxtVersion[0] > 3 || nuxtVersion[0] === 3 && nuxtVersion[1] >= 8);
|
|
242
|
+
if (nuxt3_8) {
|
|
243
|
+
nuxt.hook("nitro:build:public-assets", async () => {
|
|
227
244
|
await regeneratePWA(
|
|
228
245
|
options.outDir,
|
|
229
246
|
resolveVitePluginPWAAPI()
|
|
230
247
|
);
|
|
231
248
|
});
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
249
|
+
} else {
|
|
250
|
+
nuxt.hook("nitro:init", (nitro) => {
|
|
251
|
+
nitro.hooks.hook("rollup:before", async () => {
|
|
252
|
+
await regeneratePWA(
|
|
253
|
+
options.outDir,
|
|
254
|
+
resolveVitePluginPWAAPI()
|
|
255
|
+
);
|
|
256
|
+
});
|
|
239
257
|
});
|
|
258
|
+
if (nuxt.options._generate) {
|
|
259
|
+
nuxt.hook("close", async () => {
|
|
260
|
+
await regeneratePWA(
|
|
261
|
+
options.outDir,
|
|
262
|
+
resolveVitePluginPWAAPI()
|
|
263
|
+
);
|
|
264
|
+
});
|
|
265
|
+
}
|
|
240
266
|
}
|
|
241
267
|
}
|
|
242
268
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { UnwrapNestedRefs } from 'vue';
|
|
2
|
-
import type { PwaInjection } from './
|
|
3
|
-
import type { Plugin } from '#app
|
|
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 './
|
|
3
|
-
import type { Plugin } from '#app
|
|
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 {}
|
package/dist/types.d.mts
ADDED
|
@@ -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.
|
|
5
|
-
"packageManager": "pnpm@8.10.
|
|
4
|
+
"version": "0.3.0",
|
|
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.
|
|
26
|
-
"
|
|
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.
|
|
60
|
+
"@nuxt/kit": "^3.8.2",
|
|
65
61
|
"pathe": "^1.1.1",
|
|
66
|
-
"ufo": "^1.3.
|
|
67
|
-
"vite-plugin-pwa": ">=0.16.
|
|
62
|
+
"ufo": "^1.3.2",
|
|
63
|
+
"vite-plugin-pwa": ">=0.16.7 <1"
|
|
68
64
|
},
|
|
69
65
|
"devDependencies": {
|
|
70
|
-
"@antfu/eslint-config": "^0.
|
|
71
|
-
"@antfu/ni": "^0.21.
|
|
72
|
-
"@nuxt/module-builder": "^0.4
|
|
73
|
-
"@nuxt/schema": "^3.
|
|
74
|
-
"@nuxt/test-utils": "^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.1",
|
|
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.
|
|
74
|
+
"eslint": "^8.54.0",
|
|
79
75
|
"node-fetch-native": "^1.4.1",
|
|
80
|
-
"nuxt": "^3.
|
|
76
|
+
"nuxt": "^3.8.2",
|
|
77
|
+
"publint": "^0.2.5",
|
|
78
|
+
"rimraf": "^5.0.5",
|
|
81
79
|
"serve": "^14.2.1",
|
|
82
|
-
"typescript": "^5.
|
|
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
|