@vite-pwa/nuxt-vite 0.0.0-stage โ 2.0.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.
- package/LICENSE +21 -0
- package/README.md +61 -2
- package/dist/context-DTyDiQq1.mjs +133 -0
- package/dist/index.d.mts +2 -0
- package/dist/index.mjs +9 -0
- package/package.json +65 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023-PRESENT Anthony Fu <https://github.com/antfu>
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,62 @@
|
|
|
1
|
-
|
|
1
|
+
<p align='center'>
|
|
2
|
+
<picture>
|
|
3
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/vite-pwa/.github/main/nuxt-vite-hero-dark.svg" />
|
|
4
|
+
<img src="https://raw.githubusercontent.com/vite-pwa/.github/main/nuxt-vite-hero.svg" alt="@vite-pwa/nuxt-vite - Zero-config PWA for Nuxt with Vite Builder logo">
|
|
5
|
+
</picture>
|
|
6
|
+
</p>
|
|
2
7
|
|
|
3
|
-
|
|
8
|
+
<h1 align='center'>
|
|
9
|
+
Zero-config PWA for Nuxt with Vite Builder
|
|
10
|
+
</h1>
|
|
11
|
+
|
|
12
|
+
<p align="center">
|
|
13
|
+
Internal package used by <a href='https://github.com/vite-pwa/nuxt' target="_blank" rel="noopener noreferrer">@vite-pwa/nuxt</a> with Vite Builder. Install `@vite-pwa/nuxt` instead.
|
|
14
|
+
</p>
|
|
15
|
+
|
|
16
|
+
<p align='center'>
|
|
17
|
+
<a href='https://npmx.dev/package/@vite-pwa/nuxt-vite' target="_blank" rel="noopener noreferrer">
|
|
18
|
+
<img src='https://img.shields.io/npm/v/@vite-pwa/nuxt?color=33A6B8&label=' alt="NPM version">
|
|
19
|
+
</a>
|
|
20
|
+
<a href="https://npmx.dev/package/@vite-pwa/nuxt-vite" target="_blank" rel="noopener noreferrer">
|
|
21
|
+
<img alt="NPM Downloads" src="https://img.shields.io/npm/dm/@vite-pwa/nuxt-vite?color=476582&label=">
|
|
22
|
+
</a>
|
|
23
|
+
<a href="https://unplugin-pwa.netlify.app/frameworks/nuxt" target="__blank">
|
|
24
|
+
<img src="https://img.shields.io/static/v1?label=&message=docs%20%26%20guides&color=2e859c" alt="Docs & Guides">
|
|
25
|
+
</a>
|
|
26
|
+
<br>
|
|
27
|
+
<a href="https://github.com/vite-pwa/nuxt" target="__blank">
|
|
28
|
+
<img alt="GitHub stars" src="https://img.shields.io/github/stars/vite-pwa/nuxt?style=social">
|
|
29
|
+
</a>
|
|
30
|
+
</p>
|
|
31
|
+
|
|
32
|
+
<br>
|
|
33
|
+
|
|
34
|
+
<p align="center">
|
|
35
|
+
<a href="https://cdn.jsdelivr.net/gh/antfu/static/sponsors.svg">
|
|
36
|
+
<img src='https://cdn.jsdelivr.net/gh/antfu/static/sponsors.svg' alt="Anthony Fu SVG sponsors image"/>
|
|
37
|
+
</a>
|
|
38
|
+
</p>
|
|
39
|
+
|
|
40
|
+
## ๐ Features
|
|
41
|
+
|
|
42
|
+
- ๐ [**Documentation & guides**](https://unplugin-pwa.netlify.app/)
|
|
43
|
+
- ๐ **Zero-Config**: sensible built-in default configs for common use cases
|
|
44
|
+
- ๐ฉ **Extensible**: expose the full ability to customize the behavior of the plugin
|
|
45
|
+
- ๐ฆพ **Type Strong**: written in [TypeScript](https://www.typescriptlang.org/)
|
|
46
|
+
- ๐ **Offline Support**: generate service worker with offline support (via Workbox)
|
|
47
|
+
- โก **Fully tree shakable**: client virtual modules are strictly optimized for Dead Code Elimination.
|
|
48
|
+
- ๐ **Web Manifest**: auto-inject Web App Manifest and PWA assets seamlessly.
|
|
49
|
+
- ๐ฌ **Prompt for new content**: built-in support for Vanilla JavaScript, Vue 3, React, Svelte, SolidJS and Preact
|
|
50
|
+
- โ๏ธ **Stale-while-revalidate**: automatic reload when new content is available
|
|
51
|
+
- โจ **Static assets handling**: configure static assets for offline support
|
|
52
|
+
- ๐ **Development Support**: debug your custom service worker logic as you develop your application
|
|
53
|
+
- ๐ **Inspector**: visually inspect your resolved configuration, web manifest and service worker during development, via middleware or [DevFrame](https://github.com/devframes/devframe)
|
|
54
|
+
- ๐งฉ **Modular**: use the ready-to-use plugins or compose your own integration from the building blocks in `@unplugin-pwa/core` and `@unplugin-pwa/vite`
|
|
55
|
+
- ๐ฆ **Universal Bundlers**: native integration with Vite, Rolldown, Webpack (WIP), Rspack (WIP), and Rsbuild (WIP).
|
|
56
|
+
- ๐ ๏ธ **Meta-Frameworks**: seamless integration with [รฎles](https://github.com/ElMassimo/iles), [SvelteKit](https://github.com/sveltejs/kit), [VitePress](https://github.com/vuejs/vitepress), [Astro](https://github.com/withastro/astro), [Nuxt 3/4/5](https://github.com/nuxt/nuxt), [React Router](https://github.com/remix-run/react-router/), [TanStack](https://github.com/TanStack) and [Next](https://github.com/vercel/next.js/) (WIP).
|
|
57
|
+
- ๐ฅ **PWA Assets Generator**: generate all the PWA assets from a single command and a single source image
|
|
58
|
+
- ๐ **PWA Assets Integration**: serving, generating and injecting PWA Assets on the fly in your application
|
|
59
|
+
|
|
60
|
+
## License
|
|
61
|
+
|
|
62
|
+
[MIT](https://github.com/vite-pwa/nuxt/blob/main/LICENSE) License © 2023-PRESENT [Anthony Fu](https://github.com/antfu)
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { createCustomVitePWAContext } from "@unplugin-pwa/vite/vite-context";
|
|
2
|
+
import { addVitePlugin } from "@nuxt/kit";
|
|
3
|
+
import { DevPlugin } from "@unplugin-pwa/vite/plugins/dev";
|
|
4
|
+
import { DevMiddlewarePlugin } from "@unplugin-pwa/vite/plugins/dev-middleware";
|
|
5
|
+
import { DevAssetsMiddlewarePlugin } from "@unplugin-pwa/vite/plugins/dev-pwa-assets-middleware";
|
|
6
|
+
import { InfoPlugin } from "@unplugin-pwa/vite/plugins/info";
|
|
7
|
+
import { InspectorPlugin } from "@unplugin-pwa/vite/plugins/inspector";
|
|
8
|
+
import { MainPlugin } from "@unplugin-pwa/vite/plugins/main";
|
|
9
|
+
import { AssetsPlugin } from "@unplugin-pwa/vite/plugins/pwa-assets";
|
|
10
|
+
import { VirtualModulesPlugin } from "@unplugin-pwa/vite/plugins/virtual-modules";
|
|
11
|
+
import { exactRegex } from "@rolldown/pluginutils";
|
|
12
|
+
// src/plugins/pwa-runtime-configuration.ts
|
|
13
|
+
function PwaRuntimeConfiguration(ctx) {
|
|
14
|
+
const configuration = "virtual:nuxt-pwa-configuration";
|
|
15
|
+
const resolvedConfiguration = `\0${configuration}`;
|
|
16
|
+
return {
|
|
17
|
+
name: "vite-pwa:nuxt:runtime-configuration",
|
|
18
|
+
enforce: "pre",
|
|
19
|
+
sharedDuringBuild: true,
|
|
20
|
+
applyToEnvironment(environment) {
|
|
21
|
+
return environment.config.consumer === "client";
|
|
22
|
+
},
|
|
23
|
+
resolveId: {
|
|
24
|
+
filter: { id: exactRegex(configuration) },
|
|
25
|
+
handler(id) {
|
|
26
|
+
if (id === configuration) return resolvedConfiguration;
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
load: {
|
|
30
|
+
filter: { id: exactRegex(resolvedConfiguration) },
|
|
31
|
+
handler(id) {
|
|
32
|
+
if (id !== resolvedConfiguration) return;
|
|
33
|
+
const { client } = ctx.nuxt;
|
|
34
|
+
let callBeforeRegisterHook = false;
|
|
35
|
+
const references = [];
|
|
36
|
+
const imports = [];
|
|
37
|
+
const functions = [`export function initializeDev() {}`, `export function activateSWSwitcherDev() {}`];
|
|
38
|
+
if (ctx.devEnvironment) {
|
|
39
|
+
if (!ctx.resolvedOptions.disable && ctx.resolvedOptions.devOptions?.enabled) {
|
|
40
|
+
references.push("/// <reference types=\"@unplugin-pwa/vite/hmr-entry-point\" />");
|
|
41
|
+
imports.push("import { registerDevSW, setDevPWASwitcherReady } from 'virtual:pwa-entry-point-loaded'");
|
|
42
|
+
functions.length = 0;
|
|
43
|
+
functions.push(`export function initializeDev() { registerDevSW() }`);
|
|
44
|
+
functions.push(`export function activateSWSwitcherDev() { setDevPWASwitcherReady() }`);
|
|
45
|
+
if (ctx.dev.options.swNames.hasNames) callBeforeRegisterHook = true;
|
|
46
|
+
}
|
|
47
|
+
} else if (!ctx.resolvedOptions.disable) callBeforeRegisterHook = true;
|
|
48
|
+
const display = typeof ctx.resolvedOptions.manifest !== "boolean" ? ctx.resolvedOptions.manifest?.display ?? "standalone" : "standalone";
|
|
49
|
+
const installPrompt = typeof client.installPrompt === "undefined" || client.installPrompt === false ? void 0 : client.installPrompt === true || client.installPrompt.trim() === "" ? "vite-pwa:hide-install" : client.installPrompt.trim();
|
|
50
|
+
const exports = [
|
|
51
|
+
`export const callBeforeRegisterHook = ${callBeforeRegisterHook}`,
|
|
52
|
+
`export const enabled = ${client.registerPlugin}`,
|
|
53
|
+
`export const display = ${JSON.stringify(display)}`,
|
|
54
|
+
`export const installPrompt = ${JSON.stringify(installPrompt)}`,
|
|
55
|
+
`export const periodicSyncForUpdates = ${typeof client.periodicSyncForUpdates === "number" ? client.periodicSyncForUpdates : 0}`
|
|
56
|
+
];
|
|
57
|
+
return `${references.join("\n")}
|
|
58
|
+
${imports.join("\n")}
|
|
59
|
+
|
|
60
|
+
${functions.join("\n")}
|
|
61
|
+
|
|
62
|
+
${exports.join("\n")}
|
|
63
|
+
`;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
// src/prepare-nuxt-options.ts
|
|
69
|
+
async function prepareNuxtOptions(ctx, nuxt) {
|
|
70
|
+
const devOptions = ctx.resolvedOptions.devOptions;
|
|
71
|
+
if (nuxt.options.dev && devOptions?.enabled) {
|
|
72
|
+
const prefix = `${ctx.base}__skip_vite/`;
|
|
73
|
+
const buildAssetsDir = `${ctx.base}${ctx.nuxt.buildAssetsDir.slice(0, -1)}`;
|
|
74
|
+
ctx.dev.options.mapSWSourcemapFile = (url) => {
|
|
75
|
+
if (!url.startsWith(buildAssetsDir)) return;
|
|
76
|
+
return url.slice(buildAssetsDir.length);
|
|
77
|
+
};
|
|
78
|
+
ctx.normalizeDevServiceWorkerId = (hook, depType, id) => {
|
|
79
|
+
const useId = id.startsWith(prefix) ? id.slice(prefix.length - 1) : id;
|
|
80
|
+
if (depType === "sw") return [useId.startsWith("/") ? useId.slice(1) : useId, useId];
|
|
81
|
+
if (hook === "load") return [useId, useId];
|
|
82
|
+
const assetId = useId.startsWith("./") ? useId.slice(1) : useId;
|
|
83
|
+
return [assetId, assetId];
|
|
84
|
+
};
|
|
85
|
+
const swNames = ctx.dev.options.swNames;
|
|
86
|
+
if (swNames.hasNames) {
|
|
87
|
+
const swRoutes = ctx.resolvedOptions.swType === "classic-and-module" ? [swNames.classic, swNames.module] : [swNames.name];
|
|
88
|
+
nuxt.hook("vite:serverCreated", (viteServer, { isServer }) => {
|
|
89
|
+
if (isServer) return;
|
|
90
|
+
const next = (_req, _res, next) => next();
|
|
91
|
+
for (const route of swRoutes) {
|
|
92
|
+
viteServer.middlewares.use(`${ctx.base}${route}`, next);
|
|
93
|
+
viteServer.middlewares.use(`${ctx.base}${route}.map`, next);
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
if (devOptions?.enabled && devOptions.inspector === "vite-devtools") devOptions.inspector = "standalone";
|
|
99
|
+
addVitePlugin([
|
|
100
|
+
MainPlugin(ctx),
|
|
101
|
+
VirtualModulesPlugin(ctx),
|
|
102
|
+
InfoPlugin(ctx),
|
|
103
|
+
DevPlugin(ctx),
|
|
104
|
+
DevMiddlewarePlugin(ctx),
|
|
105
|
+
DevAssetsMiddlewarePlugin(ctx),
|
|
106
|
+
AssetsPlugin(ctx),
|
|
107
|
+
PwaRuntimeConfiguration(ctx),
|
|
108
|
+
InspectorPlugin(ctx)
|
|
109
|
+
]);
|
|
110
|
+
}
|
|
111
|
+
// src/context.ts
|
|
112
|
+
function createViteNuxtPwaContext(envApi, nuxtVersion, buildAssetsDir, options, nuxt, moduleResolver) {
|
|
113
|
+
const { builder: _builder, experimental, registerWebManifestInRouteRules, writePlugin = false, client = {}, ...pwaOptions } = options;
|
|
114
|
+
const ctx = Object.assign(createCustomVitePWAContext(envApi ? "vite" : "vite-legacy", envApi, pwaOptions), { nuxt: {
|
|
115
|
+
prepareNuxtOptions: () => prepareNuxtOptions(ctx, nuxt),
|
|
116
|
+
nuxtVersion,
|
|
117
|
+
nitroPWAOptions: { routeRules: {} },
|
|
118
|
+
buildAssetsDir,
|
|
119
|
+
client: {
|
|
120
|
+
registerPlugin: true,
|
|
121
|
+
installPrompt: false,
|
|
122
|
+
periodicSyncForUpdates: 0,
|
|
123
|
+
...client
|
|
124
|
+
},
|
|
125
|
+
experimental,
|
|
126
|
+
registerWebManifestInRouteRules,
|
|
127
|
+
writePlugin,
|
|
128
|
+
publicDirs: [],
|
|
129
|
+
moduleResolver
|
|
130
|
+
} });
|
|
131
|
+
return ctx;
|
|
132
|
+
}
|
|
133
|
+
export { createViteNuxtPwaContext };
|
package/dist/index.d.mts
ADDED
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { getMajor } from "verkit";
|
|
2
|
+
// src/index.ts
|
|
3
|
+
const builder = { build: async (nuxtVersion, buildAssetsDir, options, nuxt, moduleResolver) => {
|
|
4
|
+
const major = getMajor(nuxtVersion);
|
|
5
|
+
const envApi = major >= 5 || major === 4 && !!nuxt.options.experimental.viteEnvironmentApi;
|
|
6
|
+
const { createViteNuxtPwaContext } = await import("./context-DTyDiQq1.mjs");
|
|
7
|
+
return createViteNuxtPwaContext(envApi, nuxtVersion, buildAssetsDir, options, nuxt, moduleResolver);
|
|
8
|
+
} };
|
|
9
|
+
export { builder };
|
package/package.json
CHANGED
|
@@ -1,6 +1,68 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vite-pwa/nuxt-vite",
|
|
3
|
-
"
|
|
4
|
-
"
|
|
5
|
-
"description": "
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "2.0.1",
|
|
5
|
+
"description": "Zero-config PWA for Nuxt with Vite Builder",
|
|
6
|
+
"author": "antfu <anthonyfu117@hotmail.com>",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"funding": "https://github.com/sponsors/antfu",
|
|
9
|
+
"homepage": "https://github.com/vite-pwa/nuxt#readme",
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "git+https://github.com/vite-pwa/nuxt.git",
|
|
13
|
+
"directory": "packages/vite"
|
|
14
|
+
},
|
|
15
|
+
"bugs": "https://github.com/vite-pwa/nuxt/issues",
|
|
16
|
+
"keywords": [
|
|
17
|
+
"nuxt",
|
|
18
|
+
"pwa",
|
|
19
|
+
"workbox",
|
|
20
|
+
"unplugin-pwa",
|
|
21
|
+
"vite",
|
|
22
|
+
"vite builder"
|
|
23
|
+
],
|
|
24
|
+
"exports": {
|
|
25
|
+
".": "./dist/index.mjs",
|
|
26
|
+
"./package.json": "./package.json"
|
|
27
|
+
},
|
|
28
|
+
"types": "./dist/index.d.mts",
|
|
29
|
+
"files": [
|
|
30
|
+
"dist"
|
|
31
|
+
],
|
|
32
|
+
"peerDependencies": {
|
|
33
|
+
"@vite-pwa/assets-generator": "^1.0.0 || ^2.0.0",
|
|
34
|
+
"magicast": "^0.5.0",
|
|
35
|
+
"rolldown": "^1.0.0-0"
|
|
36
|
+
},
|
|
37
|
+
"peerDependenciesMeta": {
|
|
38
|
+
"@vite-pwa/assets-generator": {
|
|
39
|
+
"optional": true
|
|
40
|
+
},
|
|
41
|
+
"magicast": {
|
|
42
|
+
"optional": true
|
|
43
|
+
},
|
|
44
|
+
"rolldown": {
|
|
45
|
+
"optional": true
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
"dependencies": {
|
|
49
|
+
"@nuxt/kit": "^4.6.4",
|
|
50
|
+
"@rolldown/pluginutils": "^1.0.1",
|
|
51
|
+
"@unplugin-pwa/core": "^0.0.6",
|
|
52
|
+
"@unplugin-pwa/vite": "^0.0.6",
|
|
53
|
+
"@vite-pwa/nuxt-core": "2.0.1",
|
|
54
|
+
"@vite-pwa/workbox-build": "^8.0.15",
|
|
55
|
+
"verkit": "^0.5.0"
|
|
56
|
+
},
|
|
57
|
+
"devDependencies": {
|
|
58
|
+
"@nuxt/schema": "^4.6.4"
|
|
59
|
+
},
|
|
60
|
+
"publishConfig": {
|
|
61
|
+
"access": "public",
|
|
62
|
+
"provenance": true
|
|
63
|
+
},
|
|
64
|
+
"scripts": {
|
|
65
|
+
"build": "tsdown",
|
|
66
|
+
"test:typecheck": "tsc --noEmit"
|
|
67
|
+
}
|
|
6
68
|
}
|