@vite-pwa/nuxt 1.1.1 → 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.
Files changed (50) hide show
  1. package/README.md +28 -59
  2. package/config/index.d.mts +1 -0
  3. package/config/index.mjs +3 -0
  4. package/configuration.d.ts +3 -0
  5. package/dist/chunks/create-nuxt-pwa-context.mjs +27 -0
  6. package/dist/chunks/prepare-module.mjs +871 -0
  7. package/dist/chunks/prepare-pwa-icons.mjs +161 -0
  8. package/dist/module.d.mts +42 -89
  9. package/dist/module.json +4 -4
  10. package/dist/module.mjs +40 -8
  11. package/dist/runtime/components/NuxtPwaAssets.d.ts +1 -1
  12. package/dist/runtime/components/NuxtPwaAssets.js +8 -4
  13. package/dist/runtime/components/{VitePwaManifest.d.ts → NuxtPwaManifest.d.ts} +1 -1
  14. package/dist/runtime/components/{VitePwaManifest.js → NuxtPwaManifest.js} +2 -2
  15. package/dist/runtime/{composables/index.d.ts → composables.d.ts} +12 -28
  16. package/dist/runtime/{composables/index.js → composables.js} +1 -11
  17. package/dist/runtime/plugins/pwa-install.client.d.ts +6 -0
  18. package/dist/runtime/plugins/pwa-install.client.js +70 -0
  19. package/dist/runtime/plugins/pwa.client.d.ts +1 -1
  20. package/dist/runtime/plugins/pwa.client.js +90 -77
  21. package/dist/runtime/plugins/types.d.ts +70 -129
  22. package/dist/runtime/plugins/types.js +0 -0
  23. package/dist/types.d.mts +5 -5
  24. package/package.json +40 -59
  25. package/dist/chunks/dev.mjs +0 -37
  26. package/dist/chunks/pwa-icons.mjs +0 -155
  27. package/dist/module.cjs +0 -5
  28. package/dist/module.d.ts +0 -110
  29. package/dist/runtime/components/PwaAppleImage.vue +0 -12
  30. package/dist/runtime/components/PwaAppleImage.vue.d.ts +0 -2
  31. package/dist/runtime/components/PwaAppleSplashScreenImage.vue +0 -12
  32. package/dist/runtime/components/PwaAppleSplashScreenImage.vue.d.ts +0 -2
  33. package/dist/runtime/components/PwaFaviconImage.vue +0 -12
  34. package/dist/runtime/components/PwaFaviconImage.vue.d.ts +0 -2
  35. package/dist/runtime/components/PwaMaskableImage.vue +0 -12
  36. package/dist/runtime/components/PwaMaskableImage.vue.d.ts +0 -2
  37. package/dist/runtime/components/PwaTransparentImage.vue +0 -12
  38. package/dist/runtime/components/PwaTransparentImage.vue.d.ts +0 -2
  39. package/dist/runtime/components/nuxt4/PwaAppleImage.d.ts +0 -4
  40. package/dist/runtime/components/nuxt4/PwaAppleImage.js +0 -15
  41. package/dist/runtime/components/nuxt4/PwaAppleSplashScreenImage.d.ts +0 -4
  42. package/dist/runtime/components/nuxt4/PwaAppleSplashScreenImage.js +0 -15
  43. package/dist/runtime/components/nuxt4/PwaFaviconImage.d.ts +0 -4
  44. package/dist/runtime/components/nuxt4/PwaFaviconImage.js +0 -15
  45. package/dist/runtime/components/nuxt4/PwaMaskableImage.d.ts +0 -4
  46. package/dist/runtime/components/nuxt4/PwaMaskableImage.js +0 -15
  47. package/dist/runtime/components/nuxt4/PwaTransparentImage.d.ts +0 -4
  48. package/dist/runtime/components/nuxt4/PwaTransparentImage.js +0 -15
  49. package/dist/shared/nuxt.9518178d.mjs +0 -734
  50. package/dist/types.d.ts +0 -15
@@ -1,155 +0,0 @@
1
- import fs from 'node:fs';
2
- import { readFile, access } from 'node:fs/promises';
3
- import process from 'node:process';
4
- import { instructions } from '@vite-pwa/assets-generator/api/instructions';
5
- import { loadConfig } from '@vite-pwa/assets-generator/config';
6
- import { relative, basename, resolve } from 'pathe';
7
- import { p as pwaIcons, g as generatePwaImageType } from '../shared/nuxt.9518178d.mjs';
8
- import '@nuxt/kit';
9
- import 'node:path';
10
- import 'vite-plugin-pwa';
11
- import 'node:crypto';
12
-
13
- async function preparePWAIconTypes(ctx) {
14
- const { options, nuxt } = ctx;
15
- if (!options.pwaAssets || options.pwaAssets.disabled)
16
- return;
17
- const configuration = await resolvePWAAssetsOptions(ctx);
18
- if (!configuration || configuration.disabled)
19
- return;
20
- const root = nuxt.options.vite.root ?? process.cwd();
21
- const { config, sources } = await loadConfiguration(root, configuration);
22
- if (!config.preset)
23
- return;
24
- const {
25
- preset,
26
- images,
27
- headLinkOptions: userHeadLinkOptions
28
- } = config;
29
- if (!images)
30
- return;
31
- if (Array.isArray(images) && (!images.length || images.length > 1))
32
- return;
33
- const useImage = Array.isArray(images) ? images[0] : images;
34
- const imageFile = await tryToResolveImage(ctx, useImage);
35
- const publicDir = ctx.publicDirFolder;
36
- const imageName = relative(publicDir, imageFile);
37
- const xhtml = userHeadLinkOptions?.xhtml === true;
38
- const includeId = userHeadLinkOptions?.includeId === true;
39
- const assetsInstructions = await instructions({
40
- imageResolver: () => readFile(imageFile),
41
- imageName,
42
- preset,
43
- faviconPreset: userHeadLinkOptions?.preset,
44
- htmlLinks: { xhtml, includeId },
45
- basePath: nuxt.options.app.baseURL ?? "/",
46
- resolveSvgName: userHeadLinkOptions?.resolveSvgName ?? ((name) => basename(name))
47
- });
48
- const transparentNames = Object.values(assetsInstructions.transparent).map(({ name }) => name);
49
- const maskableNames = Object.values(assetsInstructions.maskable).map(({ name }) => name);
50
- const faviconNames = Object.values(assetsInstructions.favicon).map(({ name }) => name);
51
- const appleNames = Object.values(assetsInstructions.apple).map(({ name }) => name);
52
- const appleSplashScreenNames = Object.values(assetsInstructions.appleSplashScreen).map(({ name }) => name);
53
- const dts = {
54
- dts: pwaIcons({
55
- transparent: transparentNames,
56
- maskable: maskableNames,
57
- favicon: faviconNames,
58
- apple: appleNames,
59
- appleSplashScreen: appleSplashScreenNames
60
- }),
61
- transparent: generatePwaImageType("PwaTransparentImage", ctx.nuxt4, transparentNames),
62
- maskable: generatePwaImageType("PwaMaskableImage", ctx.nuxt4, maskableNames),
63
- favicon: generatePwaImageType("PwaFaviconImage", ctx.nuxt4, faviconNames),
64
- apple: generatePwaImageType("PwaAppleImage", ctx.nuxt4, appleNames),
65
- appleSplashScreen: generatePwaImageType("PwaAppleSplashScreenImage", ctx.nuxt4, appleSplashScreenNames)
66
- };
67
- if (nuxt.options.dev && nuxt.options.ssr) {
68
- sources.forEach((source) => nuxt.options.watch.push(source.replace(/\\/g, "/")));
69
- }
70
- return dts;
71
- }
72
- async function resolvePWAAssetsOptions(ctx) {
73
- const { options, nuxt } = ctx;
74
- if (!options.pwaAssets)
75
- return;
76
- const {
77
- disabled: useDisabled,
78
- config,
79
- preset,
80
- image,
81
- htmlPreset = "2023",
82
- overrideManifestIcons = false,
83
- includeHtmlHeadLinks = true,
84
- injectThemeColor = true,
85
- integration
86
- } = options.pwaAssets ?? {};
87
- const disabled = !(useDisabled === true) ? false : !config && !preset;
88
- let useImage;
89
- if (image) {
90
- useImage = await tryToResolveImage(ctx, image);
91
- } else {
92
- useImage = resolve(ctx.publicDirFolder, "favicon.svg");
93
- }
94
- useImage = relative(nuxt.options.srcDir, useImage);
95
- options.pwaAssets = {
96
- disabled,
97
- config: disabled || !config ? false : config,
98
- preset: disabled || config ? false : preset ?? "minimal-2023",
99
- image: useImage,
100
- htmlPreset,
101
- overrideManifestIcons,
102
- includeHtmlHeadLinks,
103
- injectThemeColor,
104
- integration
105
- };
106
- return {
107
- disabled,
108
- config: disabled || !config ? false : config,
109
- preset: disabled || config ? false : preset ?? "minimal-2023",
110
- images: [useImage],
111
- htmlPreset,
112
- overrideManifestIcons,
113
- includeHtmlHeadLinks,
114
- injectThemeColor,
115
- integration
116
- };
117
- }
118
- async function loadConfiguration(root, pwaAssets) {
119
- if (pwaAssets.config === false) {
120
- return await loadConfig(root, {
121
- config: false,
122
- preset: pwaAssets.preset,
123
- images: pwaAssets.images,
124
- logLevel: "silent"
125
- });
126
- }
127
- return await loadConfig(
128
- root,
129
- typeof pwaAssets.config === "boolean" ? root : { config: pwaAssets.config }
130
- );
131
- }
132
- async function checkFileExists(pathname) {
133
- try {
134
- await access(pathname, fs.constants.R_OK);
135
- } catch {
136
- return false;
137
- }
138
- return true;
139
- }
140
- async function tryToResolveImage(ctx, imageName) {
141
- for (const image of [
142
- // rootDir
143
- resolve(ctx.nuxt.options.rootDir, imageName),
144
- // srcDir
145
- resolve(ctx.nuxt.options.srcDir, imageName),
146
- // publicDir
147
- resolve(ctx.publicDirFolder, imageName)
148
- ]) {
149
- if (await checkFileExists(image))
150
- return image;
151
- }
152
- throw new Error(`PWA Assets image '${imageName}' cannot be resolved!`);
153
- }
154
-
155
- export { preparePWAIconTypes };
package/dist/module.cjs DELETED
@@ -1,5 +0,0 @@
1
- module.exports = function(...args) {
2
- return import('./module.mjs').then(m => m.default.call(this, ...args))
3
- }
4
- const _meta = module.exports.meta = require('./module.json')
5
- module.exports.getMeta = () => Promise.resolve(_meta)
package/dist/module.d.ts DELETED
@@ -1,110 +0,0 @@
1
- import * as _nuxt_schema from '@nuxt/schema';
2
- import { HookResult } from '@nuxt/schema';
3
- import { VitePWAOptions, ResolvedVitePWAOptions } from 'vite-plugin-pwa';
4
-
5
- interface ClientOptions {
6
- /**
7
- * Exposes the plugin: defaults to true.
8
- */
9
- registerPlugin?: boolean;
10
- /**
11
- * Registers a periodic sync for updates interval: value in seconds.
12
- */
13
- periodicSyncForUpdates?: number;
14
- /**
15
- * Will prevent showing native PWA install prompt: defaults to false.
16
- *
17
- * When set to true or no empty string, the native PWA install prompt will be prevented.
18
- *
19
- * When set to a string, it will be used as the key in `localStorage` to prevent show the PWA install prompt widget.
20
- *
21
- * When set to true, the key used will be `vite-pwa:hide-install`.
22
- */
23
- installPrompt?: boolean | string;
24
- }
25
- interface PwaModuleOptions extends Partial<VitePWAOptions> {
26
- /**
27
- * Experimental features.
28
- */
29
- experimental?: {
30
- /**
31
- * NOTE: this option will be ignored if using the `injectManifest` strategy or when Nuxt experimental payload
32
- * extraction is disabled.
33
- *
34
- * Enable custom runtime caching to resolve the payload.json requests with query parameters when offline:
35
- * - Workbox doesn't allow to configure `precacheAndRoute` `urlManipulation` option when using the `generateSW` strategy.
36
- * - Nuxt SSG will generate a payload.json file and will fetch it with a query parameter.
37
- * - The service worker cannot resolve the payload.json request with query parameters, and you won't get the payload when offline.
38
- *
39
- * Enabling this option will add a custom runtime caching handler to the service worker to resolve the payload files
40
- * with query parameters when offline: the runtime caching handler will redirect to the payload.json file without
41
- * query parameters when the original request fails.
42
- *
43
- * If you're using `injectManifest` strategy, you can fix the issue in your custom service worker adding the
44
- * following `urlManipulation` callback to the `precacheAndRouter` call:
45
- * ```ts
46
- * // self.__WB_MANIFEST is the default injection point
47
- * precacheAndRoute(
48
- * self.__WB_MANIFEST,
49
- * {
50
- * urlManipulation: ({ url }) => {
51
- * const urls: URL[] = []
52
- * if (url.pathname.endsWith('_payload.json')) {
53
- * const newUrl = new URL(url.href)
54
- * newUrl.search = ''
55
- * urls.push(newUrl)
56
- * }
57
- * return urls
58
- * }
59
- * }
60
- * )
61
- * ```
62
- */
63
- enableWorkboxPayloadQueryParams?: true;
64
- };
65
- registerWebManifestInRouteRules?: boolean;
66
- /**
67
- * Writes the plugin to disk: defaults to false (debug).
68
- */
69
- writePlugin?: boolean;
70
- /**
71
- * Options for plugin.
72
- */
73
- client?: ClientOptions;
74
- }
75
- interface PwaModuleHooks {
76
- 'pwa:beforeBuildServiceWorker': (options: ResolvedVitePWAOptions) => HookResult;
77
- }
78
-
79
- interface ModuleOptions extends PwaModuleOptions {
80
- }
81
- interface ModuleHooks extends PwaModuleHooks {
82
- }
83
- interface ModuleRuntimeHooks {
84
- /**
85
- * Emitted when the service worker is registered
86
- * @param data The url and the optional service worker registration object
87
- */
88
- 'service-worker:registered': (data: {
89
- url: string;
90
- registration?: ServiceWorkerRegistration;
91
- }) => HookResult;
92
- /**
93
- * Emitted when the service worker registration fails
94
- * @param data The optional error object
95
- */
96
- 'service-worker:registration-failed': (data: {
97
- error?: unknown;
98
- }) => HookResult;
99
- /**
100
- * Emitted when the service worker is activated
101
- * @param data The url and the service worker registration object
102
- */
103
- 'service-worker:activated': (data: {
104
- url: string;
105
- registration: ServiceWorkerRegistration;
106
- }) => HookResult;
107
- }
108
- declare const _default: _nuxt_schema.NuxtModule<ModuleOptions>;
109
-
110
- export { type ClientOptions, type ModuleHooks, type ModuleOptions, type ModuleRuntimeHooks, type PwaModuleHooks, type PwaModuleOptions, _default as default };
@@ -1,12 +0,0 @@
1
- <script setup lang="ts">
2
- import type { PwaAppleImageProps } from '#build/pwa-icons/PwaAppleImage'
3
- import { useApplePwaIcon } from '#pwa'
4
-
5
- const props = defineProps<PwaAppleImageProps>()
6
-
7
- const { icon } = useApplePwaIcon(props)
8
- </script>
9
-
10
- <template>
11
- <img v-if="icon" v-bind="icon">
12
- </template>
@@ -1,2 +0,0 @@
1
- const _default: typeof import('#build/pwa-icons/PwaAppleImage')['default']
2
- export default _default
@@ -1,12 +0,0 @@
1
- <script setup lang="ts">
2
- import type { PwaAppleSplashScreenImageProps } from '#build/pwa-icons/PwaAppleSplashScreenImage'
3
- import { useAppleSplashScreenPwaIcon } from '#pwa'
4
-
5
- const props = defineProps<PwaAppleSplashScreenImageProps>()
6
-
7
- const { icon } = useAppleSplashScreenPwaIcon(props)
8
- </script>
9
-
10
- <template>
11
- <img v-if="icon" v-bind="icon">
12
- </template>
@@ -1,2 +0,0 @@
1
- const _default: typeof import('#build/pwa-icons/PwaAppleSplashScreenImage')['default']
2
- export default _default
@@ -1,12 +0,0 @@
1
- <script setup lang="ts">
2
- import type { PwaFaviconImageProps } from '#build/pwa-icons/PwaFaviconImage'
3
- import { useFaviconPwaIcon } from '#pwa'
4
-
5
- const props = defineProps<PwaFaviconImageProps>()
6
-
7
- const { icon } = useFaviconPwaIcon(props)
8
- </script>
9
-
10
- <template>
11
- <img v-if="icon" v-bind="icon">
12
- </template>
@@ -1,2 +0,0 @@
1
- const _default: typeof import('#build/pwa-icons/PwaFaviconImage')['default']
2
- export default _default
@@ -1,12 +0,0 @@
1
- <script setup lang="ts">
2
- import type { PwaMaskableImageProps } from '#build/pwa-icons/PwaMaskableImage'
3
- import { useMaskablePwaIcon } from '#pwa'
4
-
5
- const props = defineProps<PwaMaskableImageProps>()
6
-
7
- const { icon } = useMaskablePwaIcon(props)
8
- </script>
9
-
10
- <template>
11
- <img v-if="icon" v-bind="icon">
12
- </template>
@@ -1,2 +0,0 @@
1
- const _default: typeof import('#build/pwa-icons/PwaMaskableImage')['default']
2
- export default _default
@@ -1,12 +0,0 @@
1
- <script setup lang="ts">
2
- import type { PwaTransparentImageProps } from '#build/pwa-icons/PwaTransparentImage'
3
- import { useTransparentPwaIcon } from '#pwa'
4
-
5
- const props = defineProps<PwaTransparentImageProps>()
6
-
7
- const { icon } = useTransparentPwaIcon(props)
8
- </script>
9
-
10
- <template>
11
- <img v-if="icon" v-bind="icon">
12
- </template>
@@ -1,2 +0,0 @@
1
- const _default: typeof import('#build/pwa-icons/PwaTransparentImage')['default']
2
- export default _default
@@ -1,4 +0,0 @@
1
- import type { PwaAppleSplashScreenImageProps } from '#build/pwa-icons/PwaAppleSplashScreenImage.d.ts';
2
- export type { PwaAppleSplashScreenImageProps };
3
- declare const _default: import("vue").DefineComponent<PwaAppleSplashScreenImageProps, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<PwaAppleSplashScreenImageProps>, {}, {}>;
4
- export default _default;
@@ -1,15 +0,0 @@
1
- import { defineComponent, h } from "#imports";
2
- import { useAppleSplashScreenPwaIcon } from "#pwa";
3
- export default defineComponent({
4
- name: "PwaAppleImage",
5
- inheritAttrs: false,
6
- setup(_, { attrs = {} }) {
7
- const { icon } = useAppleSplashScreenPwaIcon(attrs);
8
- return () => {
9
- const data = icon.value;
10
- if (!data)
11
- return;
12
- return h("img", data);
13
- };
14
- }
15
- });
@@ -1,4 +0,0 @@
1
- import type { PwaAppleImageProps } from '#build/pwa-icons/PwaAppleImage.d.ts';
2
- export type { PwaAppleImageProps };
3
- declare const _default: import("vue").DefineComponent<PwaAppleImageProps, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<PwaAppleImageProps>, {}, {}>;
4
- export default _default;
@@ -1,15 +0,0 @@
1
- import { defineComponent, h } from "#imports";
2
- import { useApplePwaIcon } from "#pwa";
3
- export default defineComponent({
4
- name: "PwaAppleImage",
5
- inheritAttrs: false,
6
- setup(_, { attrs = {} }) {
7
- const { icon } = useApplePwaIcon(attrs);
8
- return () => {
9
- const data = icon.value;
10
- if (!data)
11
- return;
12
- return h("img", data);
13
- };
14
- }
15
- });
@@ -1,4 +0,0 @@
1
- import type { PwaFaviconImageProps } from '#build/pwa-icons/PwaFaviconImage.d.ts';
2
- export type { PwaFaviconImageProps };
3
- declare const _default: import("vue").DefineComponent<PwaFaviconImageProps, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<PwaFaviconImageProps>, {}, {}>;
4
- export default _default;
@@ -1,15 +0,0 @@
1
- import { defineComponent, h } from "#imports";
2
- import { useFaviconPwaIcon } from "#pwa";
3
- export default defineComponent({
4
- name: "PwaFaviconImage",
5
- inheritAttrs: false,
6
- setup(_, { attrs = {} }) {
7
- const { icon } = useFaviconPwaIcon(attrs);
8
- return () => {
9
- const data = icon.value;
10
- if (!data)
11
- return;
12
- return h("img", data);
13
- };
14
- }
15
- });
@@ -1,4 +0,0 @@
1
- import type { PwaMaskableImageProps } from '#build/pwa-icons/PwaMaskableImage.d.ts';
2
- export type { PwaMaskableImageProps };
3
- declare const _default: import("vue").DefineComponent<PwaMaskableImageProps, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<PwaMaskableImageProps>, {}, {}>;
4
- export default _default;
@@ -1,15 +0,0 @@
1
- import { defineComponent, h } from "#imports";
2
- import { useMaskablePwaIcon } from "#pwa";
3
- export default defineComponent({
4
- name: "PwaMaskableImage",
5
- inheritAttrs: false,
6
- setup(_, { attrs = {} }) {
7
- const { icon } = useMaskablePwaIcon(attrs);
8
- return () => {
9
- const data = icon.value;
10
- if (!data)
11
- return;
12
- return h("img", data);
13
- };
14
- }
15
- });
@@ -1,4 +0,0 @@
1
- import type { PwaTransparentImageProps } from '#build/pwa-icons/PwaTransparentImage.d.ts';
2
- export type { PwaTransparentImageProps };
3
- declare const _default: import("vue").DefineComponent<PwaTransparentImageProps, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<PwaTransparentImageProps>, {}, {}>;
4
- export default _default;
@@ -1,15 +0,0 @@
1
- import { defineComponent, h } from "#imports";
2
- import { useTransparentPwaIcon } from "#pwa";
3
- export default defineComponent({
4
- name: "PwaTransparentImage",
5
- inheritAttrs: false,
6
- setup(_, { attrs = {} }) {
7
- const { icon } = useTransparentPwaIcon(attrs);
8
- return () => {
9
- const data = icon.value;
10
- if (!data)
11
- return;
12
- return h("img", data);
13
- };
14
- }
15
- });