Skip to content

Commit

Permalink
chore: simply pwa assets configuration logic
Browse files Browse the repository at this point in the history
  • Loading branch information
userquin committed Apr 5, 2024
1 parent 54730c4 commit c7ac386
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 12 deletions.
1 change: 1 addition & 0 deletions examples/assets-generator/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ 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
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' : (options.preset || 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 c7ac386

Please sign in to comment.