Skip to content

Commit

Permalink
fix: pwa assets disabled when using custom inline preset (#697)
Browse files Browse the repository at this point in the history
* fix: pwa assets disabled when using custom inline preset

* chore: simply pwa assets configuration logic
  • Loading branch information
userquin authored Apr 5, 2024
1 parent 4abcd54 commit 99ed12b
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 13 deletions.
22 changes: 22 additions & 0 deletions examples/assets-generator/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,31 @@ import { VitePWA } from 'vite-plugin-pwa'

const pwaAssets: PWAAssetsOptions = process.env.INLINE_PWA_ASSETS
? {
// disabled: false,
// config: false,
// preset: false,
/* preset: {
transparent: {
sizes: [48, 72, 96, 144, 192, 256, 384, 512], // Comprehensive sizes for various Android devices
favicons: [
[16, 'favicon-16x16.png'],
[32, 'favicon-32x32.png'],
[48, 'favicon.ico'],
],
},
maskable: {
sizes: [192, 512], // Recommended sizes for maskable icons
padding: 0,
},
apple: {
sizes: [120, 152, 167, 180, 1024], // Covers iPad and iPhone touch icons plus one for the App Store
},
}, */
image: process.env.PNG ? 'public/source-test.png' : 'public/favicon.svg',
// htmlPreset: '2023',
}
: {
// disabled: false,
config: true,
overrideManifestIcons: true,
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "vite-plugin-pwa",
"type": "module",
"version": "0.19.7",
"packageManager": "[email protected].5",
"packageManager": "[email protected].6",
"description": "Zero-config PWA for Vite",
"author": "antfu <[email protected]>",
"license": "MIT",
Expand Down
36 changes: 24 additions & 12 deletions src/pwa-assets/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ export function resolvePWAAssetsOptions(
return false

const {
disabled: useDisabled,
disabled,
preset = 'minimal-2023',
image = 'public/favicon.svg',
htmlPreset = '2023',
overrideManifestIcons = false,
Expand All @@ -16,21 +17,32 @@ export function resolvePWAAssetsOptions(
integration,
} = options ?? {}

const configIncluded = 'config' in options && options.config !== undefined && options.config
const presetIncluded = 'preset' in options && options.preset !== undefined && options.preset
const usePreset = !configIncluded && !presetIncluded ? 'minimal-2023' : false

const disabled = useDisabled || (!configIncluded && !usePreset)

return {
disabled,
config: disabled || !configIncluded ? false : configIncluded,
preset: disabled || configIncluded ? false : usePreset,
const resolvedConfiguration: ResolvedPWAAssetsOptions = {
disabled: true,
config: false,
preset: false,
images: [image],
htmlPreset,
overrideManifestIcons,
includeHtmlHeadLinks,
injectThemeColor,
integration,
} satisfies ResolvedPWAAssetsOptions
}

if (disabled === true)
return resolvedConfiguration

if ('config' in options && !!options.config) {
resolvedConfiguration.disabled = false
resolvedConfiguration.config = options.config
return resolvedConfiguration
}

if (preset === false)
return resolvedConfiguration

resolvedConfiguration.disabled = false
resolvedConfiguration.preset = preset

return resolvedConfiguration
}

0 comments on commit 99ed12b

Please sign in to comment.