@vite-pwa/nuxt 0.0.5 → 0.0.6
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 +1 -0
- package/dist/module.json +1 -1
- package/dist/module.mjs +66 -16
- package/package.json +10 -10
package/README.md
CHANGED
|
@@ -40,6 +40,7 @@ Zero-config PWA Plugin for Nuxt 3
|
|
|
40
40
|
- ⚙️ **Stale-while-revalidate**: automatic reload when new content is available
|
|
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
|
+
- 🛠️ **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)
|
|
43
44
|
|
|
44
45
|
## 📦 Install
|
|
45
46
|
|
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
|
+
import { join } from 'node:path';
|
|
2
|
+
import { writeFile, mkdir } from 'node:fs/promises';
|
|
1
3
|
import { defineNuxtModule, createResolver, addPluginTemplate, addComponent, extendWebpackConfig } from '@nuxt/kit';
|
|
2
4
|
import { VitePWA } from 'vite-plugin-pwa';
|
|
3
5
|
import { resolve } from 'pathe';
|
|
4
6
|
|
|
5
|
-
function configurePWAOptions(options, nuxt) {
|
|
7
|
+
function configurePWAOptions(options, nuxt, nitroConfig) {
|
|
6
8
|
if (!options.outDir) {
|
|
7
|
-
const publicDir =
|
|
9
|
+
const publicDir = nitroConfig.output?.publicDir;
|
|
8
10
|
options.outDir = publicDir ? resolve(publicDir) : resolve(nuxt.options.buildDir, "../.output/public");
|
|
9
11
|
}
|
|
12
|
+
if (options.devOptions?.enabled)
|
|
13
|
+
options.devOptions.resolveTempFolder = () => resolve(nuxt.options.buildDir, "dev-sw-dist");
|
|
10
14
|
let config;
|
|
11
15
|
if (options.strategies === "injectManifest") {
|
|
12
16
|
options.injectManifest = options.injectManifest ?? {};
|
|
@@ -43,6 +47,17 @@ function createManifestTransform(base) {
|
|
|
43
47
|
};
|
|
44
48
|
}
|
|
45
49
|
|
|
50
|
+
async function regeneratePWA(dir, api) {
|
|
51
|
+
if (!api || api.disabled)
|
|
52
|
+
return;
|
|
53
|
+
await api.generateSW();
|
|
54
|
+
}
|
|
55
|
+
async function writeWebManifest(dir, path, api) {
|
|
56
|
+
const manifest = api.generateBundle({})?.[path];
|
|
57
|
+
if (manifest && "source" in manifest)
|
|
58
|
+
await writeFile(resolve(dir, path), manifest.source, "utf-8");
|
|
59
|
+
}
|
|
60
|
+
|
|
46
61
|
const module = defineNuxtModule({
|
|
47
62
|
meta: {
|
|
48
63
|
name: "pwa",
|
|
@@ -71,7 +86,7 @@ const module = defineNuxtModule({
|
|
|
71
86
|
if (client.registerPlugin) {
|
|
72
87
|
addPluginTemplate({
|
|
73
88
|
src: resolver.resolve("../templates/pwa.client.ts"),
|
|
74
|
-
write: options.writePlugin,
|
|
89
|
+
write: nuxt.options.dev || options.writePlugin,
|
|
75
90
|
options: {
|
|
76
91
|
periodicSyncForUpdates: typeof client.periodicSyncForUpdates === "number" ? client.periodicSyncForUpdates : 0,
|
|
77
92
|
installPrompt: typeof client.installPrompt === "undefined" || client.installPrompt === false ? void 0 : client.installPrompt === true || client.installPrompt.trim() === "" ? "vite-pwa:hide-install" : client.installPrompt.trim()
|
|
@@ -84,11 +99,17 @@ const module = defineNuxtModule({
|
|
|
84
99
|
});
|
|
85
100
|
nuxt.hook("prepare:types", ({ references }) => {
|
|
86
101
|
references.push({ types: "vite-plugin-pwa/client" });
|
|
102
|
+
references.push({ types: "vite-plugin-pwa/info" });
|
|
87
103
|
});
|
|
88
|
-
nuxt.
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
104
|
+
const manifestDir = join(nuxt.options.buildDir, "manifests");
|
|
105
|
+
nuxt.options.nitro.publicAssets = nuxt.options.nitro.publicAssets || [];
|
|
106
|
+
nuxt.options.nitro.publicAssets.push({
|
|
107
|
+
dir: manifestDir,
|
|
108
|
+
baseURL: nuxt.options.app.baseURL,
|
|
109
|
+
maxAge: 0
|
|
110
|
+
});
|
|
111
|
+
nuxt.hook("nitro:config", (nitroConfig) => {
|
|
112
|
+
configurePWAOptions(options, nuxt, nitroConfig);
|
|
92
113
|
});
|
|
93
114
|
nuxt.hook("vite:extend", ({ config }) => {
|
|
94
115
|
const plugin = config.plugins?.find((p) => p && typeof p === "object" && "name" in p && p.name === "vite-plugin-pwa");
|
|
@@ -100,8 +121,22 @@ const module = defineNuxtModule({
|
|
|
100
121
|
const plugin = viteInlineConfig.plugins.find((p) => p && typeof p === "object" && "name" in p && p.name === "vite-plugin-pwa");
|
|
101
122
|
if (plugin)
|
|
102
123
|
throw new Error("Remove vite-plugin-pwa plugin from Vite Plugins entry in Nuxt config file!");
|
|
103
|
-
|
|
104
|
-
|
|
124
|
+
if (options.manifest && isClient) {
|
|
125
|
+
viteInlineConfig.plugins.push({
|
|
126
|
+
name: "vite-pwa-nuxt:webmanifest:build",
|
|
127
|
+
apply: "build",
|
|
128
|
+
async writeBundle(_options, bundle) {
|
|
129
|
+
if (options.disable || !bundle)
|
|
130
|
+
return;
|
|
131
|
+
const api = resolveVitePluginPWAAPI();
|
|
132
|
+
if (api) {
|
|
133
|
+
await mkdir(manifestDir, { recursive: true });
|
|
134
|
+
await writeWebManifest(manifestDir, options.manifestFilename || "manifest.webmanifest", api);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
const plugins = [...VitePWA(options).filter((p) => p.name !== "vite-plugin-pwa:build")];
|
|
105
140
|
viteInlineConfig.plugins.push(plugins);
|
|
106
141
|
if (isClient)
|
|
107
142
|
vitePwaClientPlugin = plugins.find((p) => p.name === "vite-plugin-pwa");
|
|
@@ -128,28 +163,43 @@ const module = defineNuxtModule({
|
|
|
128
163
|
return;
|
|
129
164
|
viteServer.middlewares.stack.push({ route: workbox, handle: emptyHandle });
|
|
130
165
|
});
|
|
131
|
-
nuxt.hook("close", async () => {
|
|
132
|
-
});
|
|
133
166
|
}
|
|
134
167
|
} else {
|
|
135
|
-
if (options.registerWebManifestInRouteRules) {
|
|
168
|
+
if (!options.disable && options.registerWebManifestInRouteRules) {
|
|
136
169
|
nuxt.hook("nitro:config", async (nitroConfig) => {
|
|
137
170
|
nitroConfig.routeRules = nitroConfig.routeRules || {};
|
|
138
|
-
|
|
171
|
+
let swName = options.filename || "sw.js";
|
|
172
|
+
if (options.strategies === "injectManifest" && swName.endsWith(".ts"))
|
|
173
|
+
swName = swName.replace(/\.ts$/, ".js");
|
|
174
|
+
nitroConfig.routeRules[`${nuxt.options.app.baseURL}${swName}`] = {
|
|
139
175
|
headers: {
|
|
140
|
-
"
|
|
176
|
+
"Cache-Control": "public, max-age=0, must-revalidate"
|
|
141
177
|
}
|
|
142
178
|
};
|
|
179
|
+
if (options.manifest) {
|
|
180
|
+
nitroConfig.routeRules[`${nuxt.options.app.baseURL}${options.manifestFilename ?? "manifest.webmanifest"}`] = {
|
|
181
|
+
headers: {
|
|
182
|
+
"Content-Type": "application/manifest+json",
|
|
183
|
+
"Cache-Control": "public, max-age=0, must-revalidate"
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
}
|
|
143
187
|
});
|
|
144
188
|
}
|
|
145
189
|
nuxt.hook("nitro:init", (nitro) => {
|
|
146
190
|
nitro.hooks.hook("rollup:before", async () => {
|
|
147
|
-
await
|
|
191
|
+
await regeneratePWA(
|
|
192
|
+
options.outDir,
|
|
193
|
+
resolveVitePluginPWAAPI()
|
|
194
|
+
);
|
|
148
195
|
});
|
|
149
196
|
});
|
|
150
197
|
if (nuxt.options._generate) {
|
|
151
198
|
nuxt.hook("close", async () => {
|
|
152
|
-
await
|
|
199
|
+
await regeneratePWA(
|
|
200
|
+
options.outDir,
|
|
201
|
+
resolveVitePluginPWAAPI()
|
|
202
|
+
);
|
|
153
203
|
});
|
|
154
204
|
}
|
|
155
205
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vite-pwa/nuxt",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.6",
|
|
5
5
|
"packageManager": "pnpm@7.26.1",
|
|
6
6
|
"description": "Zero-config PWA for Nuxt 3",
|
|
7
7
|
"author": "antfu <anthonyfu117@hotmail.com>",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"dev:generate": "nuxt generate playground",
|
|
40
40
|
"dev:build": "nuxi build playground",
|
|
41
41
|
"dev:prepare": "nuxt-module-build --stub && nuxi prepare playground",
|
|
42
|
-
"dev:preview": "npm run dev:build && node playground/.output/server/index.mjs",
|
|
42
|
+
"dev:preview:build": "npm run dev:build && node playground/.output/server/index.mjs",
|
|
43
43
|
"dev:preview:generate": "npm run dev:generate && npx serve playground/dist",
|
|
44
44
|
"prepublishOnly": "npm run prepack",
|
|
45
45
|
"release": "bumpp && npm publish",
|
|
@@ -51,18 +51,18 @@
|
|
|
51
51
|
"vite-plugin-pwa": "^0.14.0"
|
|
52
52
|
},
|
|
53
53
|
"dependencies": {
|
|
54
|
-
"@nuxt/kit": "^3.
|
|
55
|
-
"vite-plugin-pwa": "^0.14.
|
|
54
|
+
"@nuxt/kit": "^3.2.0",
|
|
55
|
+
"vite-plugin-pwa": "^0.14.4"
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
58
|
-
"@antfu/eslint-config": "^0.
|
|
59
|
-
"@antfu/ni": "^0.
|
|
58
|
+
"@antfu/eslint-config": "^0.35.2",
|
|
59
|
+
"@antfu/ni": "^0.20.0",
|
|
60
60
|
"@nuxt/module-builder": "^0.2.1",
|
|
61
|
-
"@nuxt/schema": "^3.
|
|
62
|
-
"@nuxt/test-utils": "^3.
|
|
61
|
+
"@nuxt/schema": "^3.2.0",
|
|
62
|
+
"@nuxt/test-utils": "^3.2.0",
|
|
63
63
|
"bumpp": "^8.2.1",
|
|
64
|
-
"eslint": "^8.
|
|
65
|
-
"nuxt": "^3.
|
|
64
|
+
"eslint": "^8.34.0",
|
|
65
|
+
"nuxt": "^3.2.0",
|
|
66
66
|
"typescript": "^4.9.5"
|
|
67
67
|
},
|
|
68
68
|
"build": {
|