vite-pwa / nuxt

Zero-config PWA Plugin for Nuxt 3
https://vite-pwa-org.netlify.app/frameworks/nuxt
MIT License
449 stars 22 forks source link

[Feature Request]: dynamic manifest.json via nitro #119

Open OrbisK opened 7 months ago

OrbisK commented 7 months ago

I think it would be a nice feature to have the possibility to keep at least some keys of the manifest file dynamic to get them from an api for example. One use case would be to change the app icon without having to create a new build.

As a proof of concept I wrote a module with a server handler that can return a manifest. (and replaced hrefs from manifest.webmanifest to my manifest route

export default defineEventHandler((event) => {
    setResponseHeaders(event, {
        "Content-Type": "application/manifest+json"
    })

    const test = Math.random() * 12
    // maybe fetch some api (configured via config) to merge default config and dynamic keys via defu

    return { /* this might be replaced by e.g. $fetch(/api/manifest-overrides) + merge with default*/
        "name": `Vitesse for Nuxt ${test}`,
        "short_name": `Vitesse for Nuxt ${test}`,
        "start_url": "/",
        "display": "standalone",
        "background_color": "#ffffff",
        "lang": "en",
        "scope": "/",
        "id": "/",
        "description": `Vitesse for Nuxt ${test}`,
        "theme_color": "#ffffff",
        "icons": [{"src": "/pwa-192x192.png", "sizes": "192x192", "type": "image/png"}, {
            "src": "/pwa-512x512.png",
            "sizes": "512x512",
            "type": "image/png"
        }, {"src": "/maskable-icon.png", "sizes": "512x512", "type": "image/png", "purpose": "any maskable"}]
    }

})

[!NOTE]
Changing the title is only for poc. It is more of a usecase to change colors, locale or images

result: image next try: image

might solve: #104

yossefAlatter commented 7 months ago

is there any solution we can make until feature added ?

yossefAlatter commented 7 months ago

please i wanna to see the repo