@vite-pwa/nuxt 0.8.1 → 0.9.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.
@@ -3,7 +3,7 @@ import { resolve, relative, basename } from 'node:path';
3
3
  import { readFile } from 'node:fs/promises';
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.12f9bd7b.mjs';
6
+ import { p as pwaIcons, g as generatePwaImageType } from '../shared/nuxt.9ac9f9c1.mjs';
7
7
  import '@nuxt/kit';
8
8
  import 'vite-plugin-pwa';
9
9
  import 'node:crypto';
package/dist/module.json CHANGED
@@ -5,5 +5,5 @@
5
5
  "nuxt": ">=3.6.5",
6
6
  "bridge": false
7
7
  },
8
- "version": "0.8.1"
8
+ "version": "0.9.1"
9
9
  }
package/dist/module.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import '@nuxt/kit';
2
- export { m as default } from './shared/nuxt.12f9bd7b.mjs';
2
+ export { m as default } from './shared/nuxt.9ac9f9c1.mjs';
3
3
  import 'node:path';
4
4
  import 'node:fs/promises';
5
5
  import 'vite-plugin-pwa';
@@ -1,4 +1,4 @@
1
- import { addTypeTemplate, addImports, createResolver, getNuxtVersion, addPlugin, addComponent, extendWebpackConfig, defineNuxtModule } from '@nuxt/kit';
1
+ import { addPluginTemplate, addTypeTemplate, addImports, createResolver, getNuxtVersion, addPlugin, addComponent, extendWebpackConfig, defineNuxtModule } from '@nuxt/kit';
2
2
  import { join } from 'node:path';
3
3
  import { lstat, writeFile, mkdir } from 'node:fs/promises';
4
4
  import { VitePWA } from 'vite-plugin-pwa';
@@ -6,7 +6,7 @@ import { createHash } from 'node:crypto';
6
6
  import { createReadStream } from 'node:fs';
7
7
  import { resolve } from 'pathe';
8
8
 
9
- const version = "0.8.1";
9
+ const version = "0.9.1";
10
10
 
11
11
  function configurePWAOptions(nuxt3_8, options, nuxt, nitroConfig) {
12
12
  if (!options.outDir) {
@@ -210,6 +210,77 @@ export default _default
210
210
  function generateTypes(types) {
211
211
  return types?.length ? types.map((name) => `'${name}'`).join(" | ") : "string";
212
212
  }
213
+ function addPWAIconsPluginTemplate(pwaAssetsEnabled) {
214
+ if (pwaAssetsEnabled) {
215
+ addPluginTemplate({
216
+ filename: "pwa-icons-plugin.ts",
217
+ name: "vite-pwa:nuxt:pwa-icons-plugin",
218
+ write: true,
219
+ getContents: () => `// Generated by @vite-pwa/nuxt
220
+ import { defineNuxtPlugin } from '#imports'
221
+ import { pwaAssetsIcons } from 'virtual:pwa-assets/icons'
222
+ import type { PWAAssetIcon, PWAIcons } from '#build/pwa-icons/pwa-icons'
223
+
224
+ export default defineNuxtPlugin(() => {
225
+ return {
226
+ provide: {
227
+ pwaIcons: {
228
+ transparent: configureEntry('transparent'),
229
+ maskable: configureEntry('maskable'),
230
+ favicon: configureEntry('favicon'),
231
+ apple: configureEntry('apple'),
232
+ appleSplashScreen: configureEntry('appleSplashScreen')
233
+ } satisfies PWAIcons
234
+ }
235
+ }
236
+ })
237
+
238
+ function configureEntry<K extends keyof PWAIcons>(key: K) {
239
+ return Object.values(pwaAssetsIcons[key] ?? {}).reduce((acc, icon) => {
240
+ const entry: PWAAssetIcon<any> = {
241
+ ...icon,
242
+ asImage: {
243
+ src: icon.url,
244
+ key: \`\${key}-\${icon.name}\`
245
+ }
246
+ }
247
+ if (icon.width && icon.height) {
248
+ entry.asImage.width = icon.width
249
+ entry.asImage.height = icon.height
250
+ }
251
+ ;(acc as unknown as any)[icon.name] = entry
252
+ return acc
253
+ }, {} as PWAIcons[typeof key])
254
+ }
255
+ `
256
+ });
257
+ } else {
258
+ addPluginTemplate({
259
+ filename: "pwa-icons-plugin.ts",
260
+ name: "vite-pwa:nuxt:pwa-icons-plugin",
261
+ write: true,
262
+ getContents: () => `// Generated by @vite-pwa/nuxt
263
+ import { defineNuxtPlugin } from '#imports'
264
+ import type { PWAAssetIcon, PWAIcons } from '#build/pwa-icons/pwa-icons'
265
+
266
+ export default defineNuxtPlugin(() => {
267
+ return {
268
+ provide: {
269
+ pwaIcons: {
270
+ transparent: {},
271
+ maskable: {},
272
+ favicon: {},
273
+ apple: {},
274
+ appleSplashScreen: {}
275
+ } satisfies PWAIcons
276
+ }
277
+ }
278
+
279
+ })
280
+ `
281
+ });
282
+ }
283
+ }
213
284
 
214
285
  async function registerPwaIconsTypes(options, nuxt, resolver, runtimeDir) {
215
286
  const pwaAssets = options.pwaAssets && !options.pwaAssets.disabled && (options.pwaAssets.config === true || !!options.pwaAssets.preset);
@@ -279,9 +350,8 @@ async function doSetup(options, nuxt) {
279
350
  mode: "client"
280
351
  });
281
352
  }
282
- addPlugin({
283
- src: resolver.resolve(runtimeDir, "plugins/pwa-icons.mjs")
284
- });
353
+ const pwaAssetsEnabled = !!options.pwaAssets && options.pwaAssets.disabled !== true;
354
+ addPWAIconsPluginTemplate(pwaAssetsEnabled);
285
355
  await Promise.all([
286
356
  addComponent({
287
357
  name: "VitePwaManifest",
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vite-pwa/nuxt",
3
3
  "type": "module",
4
- "version": "0.8.1",
4
+ "version": "0.9.1",
5
5
  "packageManager": "pnpm@9.4.0",
6
6
  "description": "Zero-config PWA for Nuxt 3",
7
7
  "author": "antfu <anthonyfu117@hotmail.com>",
@@ -1,2 +0,0 @@
1
- declare const _default: any;
2
- export default _default;
@@ -1,34 +0,0 @@
1
- import { defineNuxtPlugin } from '#imports'
2
- import { pwaAssetsIcons } from 'virtual:pwa-assets/icons'
3
-
4
- export default defineNuxtPlugin(() => {
5
- const pwaIcons = {}
6
- configureEntries(pwaIcons, 'transparent')
7
- configureEntries(pwaIcons, 'maskable')
8
- configureEntries(pwaIcons, 'favicon')
9
- configureEntries(pwaIcons, 'apple')
10
- configureEntries(pwaIcons, 'appleSplashScreen')
11
- return {
12
- provide: {
13
- pwaIcons,
14
- },
15
- }
16
- })
17
-
18
- function configureEntries(pwaIcons, key) {
19
- pwaIcons[key] = Object.values(pwaAssetsIcons[key] ?? {}).reduce((acc, icon) => {
20
- const entry = {
21
- ...icon,
22
- asImage: {
23
- src: icon.url,
24
- key: `${key}-${icon.name}`,
25
- }
26
- }
27
- if (icon.width && icon.height) {
28
- entry.asImage.width = icon.width
29
- entry.asImage.height = icon.height
30
- }
31
- acc[icon.name] = entry
32
- return acc
33
- }, {})
34
- }