@vite-pwa/nuxt 1.0.6 → 1.0.7

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.
@@ -1,19 +1,20 @@
1
- import { readFile } from 'node:fs/promises';
2
- import { resolve, relative, basename } from 'node:path';
1
+ import fs from 'node:fs';
2
+ import { readFile, access } from 'node:fs/promises';
3
3
  import process from 'node:process';
4
4
  import { instructions } from '@vite-pwa/assets-generator/api/instructions';
5
5
  import { loadConfig } from '@vite-pwa/assets-generator/config';
6
- import { p as pwaIcons, g as generatePwaImageType } from '../shared/nuxt.5d94182e.mjs';
6
+ import { relative, basename, resolve } from 'pathe';
7
+ import { p as pwaIcons, g as generatePwaImageType } from '../shared/nuxt.1f661fa7.mjs';
7
8
  import '@nuxt/kit';
9
+ import 'node:path';
8
10
  import 'vite-plugin-pwa';
9
11
  import 'node:crypto';
10
- import 'node:fs';
11
- import 'pathe';
12
12
 
13
- async function preparePWAIconTypes(options, nuxt) {
13
+ async function preparePWAIconTypes(ctx) {
14
+ const { options, nuxt } = ctx;
14
15
  if (!options.pwaAssets || options.pwaAssets.disabled)
15
16
  return;
16
- const configuration = resolvePWAAssetsOptions(options);
17
+ const configuration = await resolvePWAAssetsOptions(ctx);
17
18
  if (!configuration || configuration.disabled)
18
19
  return;
19
20
  const root = nuxt.options.vite.root ?? process.cwd();
@@ -30,13 +31,13 @@ async function preparePWAIconTypes(options, nuxt) {
30
31
  if (Array.isArray(images) && (!images.length || images.length > 1))
31
32
  return;
32
33
  const useImage = Array.isArray(images) ? images[0] : images;
33
- const imageFile = resolve(root, useImage);
34
- const publicDir = resolve(root, nuxt.options.dir.public ?? "public");
34
+ const imageFile = await tryToResolveImage(ctx, useImage);
35
+ const publicDir = ctx.publicDirFolder;
35
36
  const imageName = relative(publicDir, imageFile);
36
37
  const xhtml = userHeadLinkOptions?.xhtml === true;
37
38
  const includeId = userHeadLinkOptions?.includeId === true;
38
39
  const assetsInstructions = await instructions({
39
- imageResolver: () => readFile(resolve(root, useImage)),
40
+ imageResolver: () => readFile(imageFile),
40
41
  imageName,
41
42
  preset,
42
43
  faviconPreset: userHeadLinkOptions?.preset,
@@ -57,37 +58,56 @@ async function preparePWAIconTypes(options, nuxt) {
57
58
  apple: appleNames,
58
59
  appleSplashScreen: appleSplashScreenNames
59
60
  }),
60
- transparent: generatePwaImageType("PwaTransparentImage", transparentNames),
61
- maskable: generatePwaImageType("PwaMaskableImage", maskableNames),
62
- favicon: generatePwaImageType("PwaFaviconImage", faviconNames),
63
- apple: generatePwaImageType("PwaAppleImage", appleNames),
64
- appleSplashScreen: generatePwaImageType("PwaAppleSplashScreenImage", appleSplashScreenNames)
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)
65
66
  };
66
67
  if (nuxt.options.dev && nuxt.options.ssr) {
67
68
  sources.forEach((source) => nuxt.options.watch.push(source.replace(/\\/g, "/")));
68
69
  }
69
70
  return dts;
70
71
  }
71
- function resolvePWAAssetsOptions(options) {
72
+ async function resolvePWAAssetsOptions(ctx) {
73
+ const { options, nuxt } = ctx;
72
74
  if (!options.pwaAssets)
73
75
  return;
74
76
  const {
75
77
  disabled: useDisabled,
76
78
  config,
77
79
  preset,
78
- image = "public/favicon.svg",
80
+ image,
79
81
  htmlPreset = "2023",
80
82
  overrideManifestIcons = false,
81
83
  includeHtmlHeadLinks = true,
82
84
  injectThemeColor = true,
83
85
  integration
84
86
  } = options.pwaAssets ?? {};
85
- const disabled = useDisabled || !config && !preset;
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
+ };
86
106
  return {
87
107
  disabled,
88
108
  config: disabled || !config ? false : config,
89
109
  preset: disabled || config ? false : preset ?? "minimal-2023",
90
- images: [image],
110
+ images: [useImage],
91
111
  htmlPreset,
92
112
  overrideManifestIcons,
93
113
  includeHtmlHeadLinks,
@@ -109,5 +129,27 @@ async function loadConfiguration(root, pwaAssets) {
109
129
  typeof pwaAssets.config === "boolean" ? root : { config: pwaAssets.config }
110
130
  );
111
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
+ }
112
154
 
113
155
  export { preparePWAIconTypes };
package/dist/module.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "compatibility": {
5
5
  "nuxt": ">=3.6.5"
6
6
  },
7
- "version": "1.0.6",
7
+ "version": "1.0.7",
8
8
  "builder": {
9
9
  "@nuxt/module-builder": "0.8.3",
10
10
  "unbuild": "2.0.0"
package/dist/module.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import '@nuxt/kit';
2
- export { m as default } from './shared/nuxt.5d94182e.mjs';
2
+ export { m as default } from './shared/nuxt.1f661fa7.mjs';
3
3
  import 'node:fs/promises';
4
4
  import 'node:path';
5
5
  import 'vite-plugin-pwa';
@@ -0,0 +1,4 @@
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;
@@ -0,0 +1,15 @@
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
+ });
@@ -0,0 +1,4 @@
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;
@@ -0,0 +1,15 @@
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
+ });
@@ -0,0 +1,4 @@
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;
@@ -0,0 +1,15 @@
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
+ });
@@ -0,0 +1,4 @@
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;
@@ -0,0 +1,15 @@
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
+ });
@@ -0,0 +1,4 @@
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;
@@ -0,0 +1,15 @@
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
+ });
@@ -28,7 +28,7 @@ export interface PWAIcon {
28
28
  nonce?: string;
29
29
  [key: string]: any;
30
30
  }
31
- type PWAImageType<T> = T extends 'transparent' ? PwaTransparentImageProps['image'] | (Omit<PWAImage, 'image'> & {
31
+ export type PWAImageType<T> = T extends 'transparent' ? PwaTransparentImageProps['image'] | (Omit<PWAImage, 'image'> & {
32
32
  image: PwaTransparentImageProps['image'];
33
33
  }) : T extends 'maskable' ? PwaMaskableImageProps['image'] | Omit<PWAImage, 'image'> & {
34
34
  image: PwaMaskableImageProps['image'];
@@ -60,4 +60,3 @@ export declare function useAppleSplashScreenPwaIcon(image: AppleSplashScreenImag
60
60
  icon: import("vue").ComputedRef<PWAIcon | undefined>;
61
61
  };
62
62
  export declare function usePWA(): UnwrapNestedRefs<PwaInjection> | undefined;
63
- export {};
@@ -1,4 +1,4 @@
1
- import { addPluginTemplate, addTypeTemplate, addImports, createResolver, getNuxtVersion, addPlugin, addComponent, extendWebpackConfig, addDevServerHandler, defineNuxtModule } from '@nuxt/kit';
1
+ import { addPluginTemplate, addTypeTemplate, addImports, createResolver, getNuxtVersion, resolveAlias, addPlugin, addComponent, extendWebpackConfig, addDevServerHandler, defineNuxtModule } from '@nuxt/kit';
2
2
  import { lstat, writeFile, mkdir } from 'node:fs/promises';
3
3
  import { join } from 'node:path';
4
4
  import { VitePWA } from 'vite-plugin-pwa';
@@ -6,9 +6,10 @@ import { createHash } from 'node:crypto';
6
6
  import { createReadStream } from 'node:fs';
7
7
  import { resolve } from 'pathe';
8
8
 
9
- const version = "1.0.6";
9
+ const version = "1.0.7";
10
10
 
11
- function configurePWAOptions(nuxt3_8, options, nuxt, nitroConfig) {
11
+ function configurePWAOptions(ctx, nitroConfig) {
12
+ const { nuxt3_8, options, nuxt } = ctx;
12
13
  if (!options.outDir) {
13
14
  const publicDir = nitroConfig.output?.publicDir ?? nuxt.options.nitro?.output?.publicDir;
14
15
  options.outDir = publicDir ? resolve(publicDir) : resolve(nuxt.options.buildDir, "../.output/public");
@@ -81,7 +82,7 @@ function configurePWAOptions(nuxt3_8, options, nuxt, nitroConfig) {
81
82
  if (options.pwaAssets) {
82
83
  options.pwaAssets.integration = {
83
84
  baseUrl: nuxt.options.app.baseURL ?? "/",
84
- publicDir: nuxt.options.dir.public,
85
+ publicDir: ctx.publicDirFolder,
85
86
  outDir: options.outDir
86
87
  };
87
88
  }
@@ -143,19 +144,19 @@ function createManifestTransform(base, publicFolder, appManifestFolder) {
143
144
  };
144
145
  }
145
146
 
146
- function addPwaTypeTemplate(filename, content) {
147
+ function addPwaTypeTemplate(filename, isNuxt4, content) {
147
148
  if (content?.length) {
148
- addTypeTemplate({
149
+ return addTypeTemplate({
149
150
  write: true,
150
151
  filename: `pwa-icons/${filename}.d.ts`,
151
152
  getContents: () => content
152
- });
153
+ }).dst;
153
154
  } else {
154
- addTypeTemplate({
155
+ return addTypeTemplate({
155
156
  write: true,
156
- getContents: () => generatePwaImageType(filename),
157
+ getContents: () => generatePwaImageType(filename, isNuxt4),
157
158
  filename: `pwa-icons/${filename}.d.ts`
158
- });
159
+ }).dst;
159
160
  }
160
161
  }
161
162
  function pwaIcons(types) {
@@ -194,8 +195,22 @@ declare module 'vue' {
194
195
  export {}
195
196
  `;
196
197
  }
197
- function generatePwaImageType(filename, names) {
198
+ function generatePwaImageType(filename, isNuxt4, names) {
198
199
  const propsName = `${filename}Props`;
200
+ if (isNuxt4) {
201
+ return `// Generated by @vite-pwa/nuxt
202
+ export interface ${propsName} {
203
+ image: ${generateTypes(names)}
204
+ alt?: string
205
+ width?: number
206
+ height?: number
207
+ crossorigin?: '' | 'anonymous' | 'use-credentials'
208
+ loading?: 'lazy' | 'eager'
209
+ decoding?: 'async' | 'auto' | 'sync'
210
+ nonce?: string
211
+ }
212
+ `;
213
+ }
199
214
  return `// Generated by @vite-pwa/nuxt
200
215
  export interface ${propsName} {
201
216
  image: ${generateTypes(names)}
@@ -294,18 +309,19 @@ export default defineNuxtPlugin(() => {
294
309
  }
295
310
  }
296
311
 
297
- async function registerPwaIconsTypes(options, nuxt, resolver, runtimeDir) {
298
- const pwaAssets = options.pwaAssets && !options.pwaAssets.disabled && (options.pwaAssets.config === true || !!options.pwaAssets.preset);
312
+ async function registerPwaIconsTypes(ctx, runtimeDir) {
313
+ const { options, nuxt, resolver } = ctx;
314
+ const pwaAssets = options.pwaAssets && !options.pwaAssets.disabled;
299
315
  let dts;
300
316
  if (pwaAssets) {
301
317
  try {
302
318
  const { preparePWAIconTypes } = await import('../chunks/pwa-icons.mjs');
303
- dts = await preparePWAIconTypes(options, nuxt);
319
+ dts = await preparePWAIconTypes(ctx);
304
320
  } catch {
305
321
  dts = void 0;
306
322
  }
307
323
  }
308
- nuxt.options.alias["#pwa"] = resolver.resolve(runtimeDir, "composables/index.js");
324
+ nuxt.options.alias["#pwa"] = resolver.resolve(runtimeDir, "composables/index");
309
325
  nuxt.options.build.transpile.push("#pwa");
310
326
  addImports([
311
327
  "usePWA",
@@ -319,25 +335,35 @@ async function registerPwaIconsTypes(options, nuxt, resolver, runtimeDir) {
319
335
  as: key,
320
336
  from: resolver.resolve(runtimeDir, "composables/index")
321
337
  })));
338
+ const templates = [];
339
+ const isNuxt4 = ctx.nuxt4;
322
340
  const dtsContent = dts?.dts;
323
341
  if (dtsContent) {
324
- addTypeTemplate({
342
+ templates.push(addTypeTemplate({
325
343
  write: true,
326
344
  filename: "pwa-icons/pwa-icons.d.ts",
327
345
  getContents: () => dtsContent
328
- });
346
+ }).dst);
329
347
  } else {
330
- addTypeTemplate({
348
+ templates.push(addTypeTemplate({
331
349
  write: true,
332
350
  filename: "pwa-icons/pwa-icons.d.ts",
333
351
  getContents: () => pwaIcons()
352
+ }).dst);
353
+ }
354
+ templates.push(addPwaTypeTemplate("PwaTransparentImage", isNuxt4, dts?.transparent));
355
+ templates.push(addPwaTypeTemplate("PwaMaskableImage", isNuxt4, dts?.maskable));
356
+ templates.push(addPwaTypeTemplate("PwaFaviconImage", isNuxt4, dts?.favicon));
357
+ templates.push(addPwaTypeTemplate("PwaAppleImage", isNuxt4, dts?.apple));
358
+ templates.push(addPwaTypeTemplate("PwaAppleSplashScreenImage", isNuxt4, dts?.appleSplashScreen));
359
+ if (ctx.nuxt4) {
360
+ ctx.nuxt.hook("prepare:types", (context) => {
361
+ const nodeReferences = context.nodeReferences;
362
+ for (const path of templates) {
363
+ nodeReferences.push({ path });
364
+ }
334
365
  });
335
366
  }
336
- addPwaTypeTemplate("PwaTransparentImage", dts?.transparent);
337
- addPwaTypeTemplate("PwaMaskableImage", dts?.maskable);
338
- addPwaTypeTemplate("PwaFaviconImage", dts?.favicon);
339
- addPwaTypeTemplate("PwaAppleImage", dts?.apple);
340
- addPwaTypeTemplate("PwaAppleSplashScreenImage", dts?.appleSplashScreen);
341
367
  return !!dts;
342
368
  }
343
369
 
@@ -366,6 +392,19 @@ async function doSetup(options, nuxt) {
366
392
  const resolver = createResolver(import.meta.url);
367
393
  const nuxtVersion = getNuxtVersion(nuxt).split(".").map((v) => Number.parseInt(v));
368
394
  const nuxt3_8 = nuxtVersion.length > 1 && (nuxtVersion[0] > 3 || nuxtVersion[0] === 3 && nuxtVersion[1] >= 8);
395
+ const nuxt4 = nuxtVersion.length > 1 && nuxtVersion[0] >= 4;
396
+ const future = nuxt.options.future;
397
+ const ctx = {
398
+ nuxt,
399
+ nuxt3_8,
400
+ nuxt4,
401
+ // included at v3.12.0, then removed and included back again for v5 compatibility: we only need the layout to configure correctly the pwa assets image
402
+ // https://github.com/nuxt/nuxt/releases/tag/v3.12.0
403
+ nuxt4Compat: nuxt4 ? true : "compatibilityVersion" in future && typeof future.compatibilityVersion === "number" && future.compatibilityVersion >= 4,
404
+ resolver: createResolver(import.meta.url),
405
+ options,
406
+ publicDirFolder: resolveAlias("public")
407
+ };
369
408
  let vitePwaClientPlugin;
370
409
  const resolveVitePluginPWAAPI = () => {
371
410
  return vitePwaClientPlugin?.api;
@@ -376,8 +415,7 @@ async function doSetup(options, nuxt) {
376
415
  periodicSyncForUpdates: 0
377
416
  };
378
417
  const runtimeDir = resolver.resolve("../runtime");
379
- if (!nuxt.options.ssr)
380
- nuxt.options.build.transpile.push(runtimeDir);
418
+ nuxt.options.build.transpile.push(runtimeDir);
381
419
  if (client.registerPlugin) {
382
420
  addPlugin({
383
421
  src: resolver.resolve(runtimeDir, "plugins/pwa.client"),
@@ -386,40 +424,77 @@ async function doSetup(options, nuxt) {
386
424
  }
387
425
  const pwaAssetsEnabled = !!options.pwaAssets && options.pwaAssets.disabled !== true;
388
426
  addPWAIconsPluginTemplate(pwaAssetsEnabled);
389
- await Promise.all([
390
- addComponent({
391
- name: "VitePwaManifest",
392
- filePath: resolver.resolve(runtimeDir, "components/VitePwaManifest")
393
- }),
394
- addComponent({
395
- name: "NuxtPwaManifest",
396
- filePath: resolver.resolve(runtimeDir, "components/VitePwaManifest")
397
- }),
398
- addComponent({
399
- name: "NuxtPwaAssets",
400
- filePath: resolver.resolve(runtimeDir, "components/NuxtPwaAssets")
401
- }),
402
- addComponent({
403
- name: "PwaAppleImage",
404
- filePath: resolver.resolve(runtimeDir, "components/PwaAppleImage.vue")
405
- }),
406
- addComponent({
407
- name: "PwaAppleSplashScreenImage",
408
- filePath: resolver.resolve(runtimeDir, "components/PwaAppleSplashScreenImage.vue")
409
- }),
410
- addComponent({
411
- name: "PwaFaviconImage",
412
- filePath: resolver.resolve(runtimeDir, "components/PwaFaviconImage.vue")
413
- }),
414
- addComponent({
415
- name: "PwaMaskableImage",
416
- filePath: resolver.resolve(runtimeDir, "components/PwaMaskableImage.vue")
417
- }),
418
- addComponent({
419
- name: "PwaTransparentImage",
420
- filePath: resolver.resolve(runtimeDir, "components/PwaTransparentImage.vue")
421
- })
422
- ]);
427
+ if (ctx.nuxt4) {
428
+ await Promise.all([
429
+ addComponent({
430
+ name: "VitePwaManifest",
431
+ filePath: resolver.resolve(runtimeDir, "components/VitePwaManifest")
432
+ }),
433
+ addComponent({
434
+ name: "NuxtPwaManifest",
435
+ filePath: resolver.resolve(runtimeDir, "components/VitePwaManifest")
436
+ }),
437
+ addComponent({
438
+ name: "NuxtPwaAssets",
439
+ filePath: resolver.resolve(runtimeDir, "components/NuxtPwaAssets")
440
+ }),
441
+ addComponent({
442
+ name: "PwaAppleImage",
443
+ filePath: resolver.resolve(runtimeDir, "components/nuxt4/PwaAppleImage")
444
+ }),
445
+ addComponent({
446
+ name: "PwaAppleSplashScreenImage",
447
+ filePath: resolver.resolve(runtimeDir, "components/nuxt4/PwaAppleSplashScreenImage")
448
+ }),
449
+ addComponent({
450
+ name: "PwaFaviconImage",
451
+ filePath: resolver.resolve(runtimeDir, "components/nuxt4/PwaFaviconImage")
452
+ }),
453
+ addComponent({
454
+ name: "PwaMaskableImage",
455
+ filePath: resolver.resolve(runtimeDir, "components/nuxt4/PwaMaskableImage")
456
+ }),
457
+ addComponent({
458
+ name: "PwaTransparentImage",
459
+ filePath: resolver.resolve(runtimeDir, "components/nuxt4/PwaTransparentImage")
460
+ })
461
+ ]);
462
+ } else {
463
+ await Promise.all([
464
+ addComponent({
465
+ name: "VitePwaManifest",
466
+ filePath: resolver.resolve(runtimeDir, "components/VitePwaManifest")
467
+ }),
468
+ addComponent({
469
+ name: "NuxtPwaManifest",
470
+ filePath: resolver.resolve(runtimeDir, "components/VitePwaManifest")
471
+ }),
472
+ addComponent({
473
+ name: "NuxtPwaAssets",
474
+ filePath: resolver.resolve(runtimeDir, "components/NuxtPwaAssets")
475
+ }),
476
+ addComponent({
477
+ name: "PwaAppleImage",
478
+ filePath: resolver.resolve(runtimeDir, "components/PwaAppleImage.vue")
479
+ }),
480
+ addComponent({
481
+ name: "PwaAppleSplashScreenImage",
482
+ filePath: resolver.resolve(runtimeDir, "components/PwaAppleSplashScreenImage.vue")
483
+ }),
484
+ addComponent({
485
+ name: "PwaFaviconImage",
486
+ filePath: resolver.resolve(runtimeDir, "components/PwaFaviconImage.vue")
487
+ }),
488
+ addComponent({
489
+ name: "PwaMaskableImage",
490
+ filePath: resolver.resolve(runtimeDir, "components/PwaMaskableImage.vue")
491
+ }),
492
+ addComponent({
493
+ name: "PwaTransparentImage",
494
+ filePath: resolver.resolve(runtimeDir, "components/PwaTransparentImage.vue")
495
+ })
496
+ ]);
497
+ }
423
498
  nuxt.hook("prepare:types", ({ references }) => {
424
499
  references.push({ path: resolver.resolve(runtimeDir, "plugins/types") });
425
500
  references.push({ types: "@vite-pwa/nuxt/configuration" });
@@ -427,7 +502,7 @@ async function doSetup(options, nuxt) {
427
502
  references.push({ types: "vite-plugin-pwa/info" });
428
503
  references.push({ types: "vite-plugin-pwa/pwa-assets" });
429
504
  });
430
- const pwaAssets = await registerPwaIconsTypes(options, nuxt, resolver, runtimeDir);
505
+ const pwaAssets = await registerPwaIconsTypes(ctx, runtimeDir);
431
506
  const manifestDir = join(nuxt.options.buildDir, "manifests");
432
507
  nuxt.options.nitro.publicAssets = nuxt.options.nitro.publicAssets || [];
433
508
  nuxt.options.nitro.publicAssets.push({
@@ -435,7 +510,7 @@ async function doSetup(options, nuxt) {
435
510
  maxAge: 0
436
511
  });
437
512
  nuxt.hook("nitro:init", (nitro) => {
438
- configurePWAOptions(nuxt3_8, options, nuxt, nitro.options);
513
+ configurePWAOptions(ctx, nitro.options);
439
514
  });
440
515
  nuxt.hook("vite:extend", ({ config }) => {
441
516
  const plugin = config.plugins?.find((p) => p && typeof p === "object" && "name" in p && p.name === "vite-plugin-pwa");
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vite-pwa/nuxt",
3
3
  "type": "module",
4
- "version": "1.0.6",
4
+ "version": "1.0.7",
5
5
  "description": "Zero-config PWA for Nuxt 3",
6
6
  "author": "antfu <anthonyfu117@hotmail.com>",
7
7
  "license": "MIT",
@@ -98,6 +98,10 @@
98
98
  "dev:prepare": "nuxt-module-build build --stub && nuxt-module-build prepare && nuxi prepare playground",
99
99
  "dev:preview:build": "nr dev:build && node playground/.output/server/index.mjs",
100
100
  "dev:preview:generate": "nr dev:generate && serve playground/dist",
101
+ "dev:assets:prepare": "nuxt-module-build build --stub && nuxt-module-build prepare && nuxi prepare playground-assets",
102
+ "dev:assets": "nr dev:assets:prepare && nuxi dev playground-assets",
103
+ "dev:assets:generate": "nr dev:assets:prepare && nuxi generate playground-assets",
104
+ "dev:assets:build": "nr dev:assets:prepare && nuxi build playground-assets",
101
105
  "release": "bumpp",
102
106
  "lint": "eslint .",
103
107
  "lint:fix": "nr lint --fix",