nuxt-community / pwa-module

Zero config PWA solution for Nuxt.js
https://pwa.nuxtjs.org
MIT License
1.24k stars 171 forks source link

Allow separate icon settings for maskable #494

Open rotsee opened 2 years ago

rotsee commented 2 years ago

Almost always you want to have two different variants of your logo in your manifest: Maskable, and regular icons (see e.g. https://web.dev/maskable-icon/). In fact, Google Chrome will even warn developers when using the same version. The side effects of not providing separate icons are that icons will look weird somewhere; On iOS, on Android, when adding a desktop shortcut to Gnome, etc, etc.

It would be truly great if the icon module could handle this for us! E.g. by allowing something like this in the options:

    icon: {
          icons: [{
            "src": "/assets/icon-maskable.png",
            "purpose": "maskable",
          }, {
            "src": "/assets/icon.png",
            "purpose": "any",
          }:],
    }

...while still generating all the sizes etc.

This is related to the following:

JOODHAEWOOJAE commented 2 years ago

Hi. Do you have any news about this issue?

joerees commented 2 years ago

It would be good if we can add multiple icon settings, as mentioned above to add maskable to specific sizes, not all.

Will there be a fix for this issue ?

Migushthe2nd commented 1 year ago

Purpose "maskable any" is actually discouraged and rejected by tools like www.pwabuilder.com, so being able to define icons separately is crucial.

Check out https://github.com/pwa-builder/PWABuilder/issues/2379

jundellagbo commented 1 year ago

@rotsee @joerees @JOODHAEWOOJAE

Here is my solution for this, you have to create your own manifest.json in "static" folder and change your manifest URL instead of nuxt generated.

static/manifest.json static/pwa/any/icon-512x512.png static/pwa/maskable/icon-512x512.png

~ /static/manifest.json

{
    "name": "My App,
    "short_name": "My App",
    "description": "My Description,
    "icons": [
      {
        "src": "/pwa/any/icon-512x512.png",
        "sizes": "512x512",
        "type": "image/png",
        "purpose": "any"
      },
      {
        "src": "/pwa/maskable/icon-512x512.png",
        "sizes": "512x512",
        "type": "image/png",
        "purpose": "maskable"
      }
    ],
    "start_url": "/?standalone=true",
    "display": "standalone",
    "background_color": "#ffffff",
    "theme_color": "#1a73e8",
    "lang": "en"
  }

and modify nuxt.config.js under "head" option.

~ nuxt.config.js

export default {
  head: {
    link: [
      {
        hid: 'manifest',
        rel: 'manifest',
        'data-n-head': 'ssr',
        href: '/manifest.json'
      }
    ]
  }
}

Here you can also visit your manifest.json https://myapp.com/manifest.json

I tried this in www.pwabuilder.com and it works.

Also you can generate maskable icon here https://maskable.app/editor

Migushthe2nd commented 1 year ago

@jundellagbo

I've done it using a PWA config similar to the one below:

{
    pwa: {
        manifest: {
            icons: [
                // we want to define 'any' icon type manually, because icon module will create icons with type 'maskable'
                ...["64x64", "120x120", "144x144", "152x152", "192x192", "384x384", "512x512"].map(size => ({
                    src: `/icons/any/${size}.png`,
                    sizes: size,
                    type: "image/png",
                    purpose: "any"
                }))
            ],
        },
        icon: {
            fileName: "icon_maskable.png",
            purpose: ["maskable"],
        }
    }
}

Though, you'd have to manually create all icon variants. There's most certainly a way to automate it, but I couldn't be bothered. You could also disable the module's icon generation all together and add another of those mappings for the maskable type.

jundellagbo commented 1 year ago

@Migushthe2nd

I already tried that but it is still combining the "purpose" with "any maskable".

Migushthe2nd commented 1 year ago

It works for me as the are only 'any' and 'maskable' separately