Skip to content

Commit

Permalink
fix: pwa assets disabled when using inlined configuration (#685)
Browse files Browse the repository at this point in the history
* fix: pwa assets disabled when using inlined configuration

* chore: fix lint
  • Loading branch information
userquin authored Mar 14, 2024
1 parent 0d094ac commit 7ffeb44
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 24 deletions.
10 changes: 8 additions & 2 deletions examples/assets-generator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,22 @@
"preview": "vite preview",
"dev:png": "PNG=true vite",
"build:png": "PNG=true vite build",
"preview:png": "PNG=true vite preview"
"preview:png": "PNG=true vite preview",
"dev:inline:svg": "INLINE_PWA_ASSETS=true vite",
"build:inline:svg": "INLINE_PWA_ASSETS=true vite build",
"preview:inline:svg": "INLINE_PWA_ASSETS=true vite preview",
"dev:inline:png": "INLINE_PWA_ASSETS=true PNG=true vite",
"build:inline:png": "INLINE_PWA_ASSETS=true PNG=true vite build",
"preview:inline:png": "INLINE_PWA_ASSETS=true PNG=true vite preview"
},
"devDependencies": {
"@vite-pwa/assets-generator": "^0.2.4",
"rimraf": "^5.0.5",
"sharp": "^0.32.6",
"sharp-ico": "^0.1.5",
"typescript": "^5.3.3",
"vite": "^5.0.10",
"vite-plugin-pwa": "workspace:*",
"@vite-pwa/assets-generator": "^0.2.4",
"workbox-window": "^7.0.0"
}
}
15 changes: 11 additions & 4 deletions examples/assets-generator/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
import { defineConfig } from 'vite'
import type { PWAAssetsOptions } from 'vite-plugin-pwa'
import { VitePWA } from 'vite-plugin-pwa'

const pwaAssets: PWAAssetsOptions = process.env.INLINE_PWA_ASSETS
? {
image: process.env.PNG ? 'public/source-test.png' : 'public/favicon.svg',
}
: {
config: true,
overrideManifestIcons: true,
}

export default defineConfig({
logLevel: 'info',
define: {
Expand All @@ -22,10 +32,7 @@ export default defineConfig({
short_name: 'Vite PWA',
theme_color: '#ffffff',
},
pwaAssets: {
config: true,
overrideManifestIcons: true,
},
pwaAssets,
workbox: {
globPatterns: ['**/*.{js,css,html,png,svg,ico}'],
cleanupOutdatedCaches: true,
Expand Down
4 changes: 2 additions & 2 deletions examples/vanilla-js-custom-sw/package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "vanilla-js-custom-sw",
"private": true,
"version": "0.0.0",
"type": "module",
"version": "0.0.0",
"private": true,
"scripts": {
"dev": "vite",
"build": "vite build",
Expand Down
22 changes: 11 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,17 @@
"test": "nr test-vue && nr test-react && nr test-preact && nr test-solid && nr test-svelte && nr test-typescript",
"test:vite-ecosystem-ci": "nr test-typescript"
},
"peerDependencies": {
"@vite-pwa/assets-generator": "^0.2.4",
"vite": "^3.1.0 || ^4.0.0 || ^5.0.0",
"workbox-build": "^7.0.0",
"workbox-window": "^7.0.0"
},
"peerDependenciesMeta": {
"@vite-pwa/assets-generator": {
"optional": true
}
},
"dependencies": {
"debug": "^4.3.4",
"fast-glob": "^3.3.2",
Expand Down Expand Up @@ -141,16 +152,5 @@
"vite": "^5.0.12",
"vitest": "1.0.0-beta.4",
"vue": "^3.3.8"
},
"peerDependencies": {
"@vite-pwa/assets-generator": "^0.2.4",
"vite": "^3.1.0 || ^4.0.0 || ^5.0.0",
"workbox-build": "^7.0.0",
"workbox-window": "^7.0.0"
},
"peerDependenciesMeta": {
"@vite-pwa/assets-generator": {
"optional": true
}
}
}
12 changes: 7 additions & 5 deletions src/pwa-assets/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ export function resolvePWAAssetsOptions(

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

const disabled = useDisabled || (!config && !preset)
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 || !config ? false : config,
preset: disabled || config ? false : preset ?? 'minimal-2023',
config: disabled || !configIncluded ? false : configIncluded,
preset: disabled || configIncluded ? false : usePreset,
images: [image],
htmlPreset,
overrideManifestIcons,
Expand Down

0 comments on commit 7ffeb44

Please sign in to comment.