vite-plugin-pwa icon indicating copy to clipboard operation
vite-plugin-pwa copied to clipboard

feat: automatic generation and injection of favicon

Open jacekkarczmarczyk opened this issue 3 years ago • 10 comments

There's a favicon plugin for webpack https://github.com/jantimon/favicons-webpack-plugin which given the single image file automatically creates small icons and injects them to index.html

Providing such functionality to this PWA plugin would be a nice thing too - it would inject icons to the manifest section of the plugin configuration, to the entry file (index.html) and to dist/assets.

jacekkarczmarczyk avatar Feb 06 '22 14:02 jacekkarczmarczyk

Found this package looking specifically for this feature — I'm using Sveltekit and service workers are already reasonably straightforward there, but generating and injecting an iconset into a manifest would be a big productivity win on new projects

madeleineostoja avatar Feb 11 '22 10:02 madeleineostoja

@jacekkarczmarczyk Maybe it would be better to add a cli to generate the icons since the process will be too expensive, then we can transform the index.html using the cli or just adding another plugin with a transform html hook (on dev and on build).

I'm testing this vite plugin https://github.com/josh-hemphill/vite-plugin-favicon/, but the generation is wrong since it is using the assets directory and the manifest is not being updated to use the icons with hashed name (when integrated here, we need to exclude the manifest.webmanifest generation). Since the pwa plugin is using workbox-build (file based), it would be better to use the public directory, all generated icons will go there and also added to the sw pre cache manifest, so if we change the icons the sw will change also their hash. Once the icons are generated on the public directory we can use them from any asset.

If we include a plugin with a similar fashion to previous one, icons will not be generated on development, just starting the dev server will take more than 10 seconds, and that is not what we want.

userquin avatar Feb 11 '22 20:02 userquin

I don't know vite internals but I'm pretty sure it could be done with some caching, obviously first time would be expensive, but next time images would be taken from the cache (unless the original image has changed)

jacekkarczmarczyk avatar Feb 11 '22 20:02 jacekkarczmarczyk

ok, I'll try do to some test

userquin avatar Feb 11 '22 20:02 userquin

@jacekkarczmarczyk there is plugin for VS Code from microsoft (PWABuilder), maybe it would be better to use it instead integrating the logic here, I've not tested it yet (I use IntelliJ EE):

https://github.com/pwa-builder/pwa-studio

userquin avatar Apr 01 '22 18:04 userquin

I use IntelliJ EE

Me too, also not sure if VS Code plugin would be usable in automatic CI etc

jacekkarczmarczyk avatar Apr 01 '22 18:04 jacekkarczmarczyk

@jacekkarczmarczyk can you take a look at this one PWA Asset Generator ? You can also generate splash for installed PWA.

I'll take a look to try to integrate here, including also pwa icons injection on html (the library allow us to use it also as a module).

FYI: https://web.dev/learn/pwa/enhancements/ on Learn PWA from Google

userquin avatar Apr 21 '22 10:04 userquin

Will do, thanks. This link from Google looks cool too!

jacekkarczmarczyk avatar Apr 21 '22 10:04 jacekkarczmarczyk

Will do, thanks. This link from Google looks cool too!

FYI: The link to Learn PWA is also included on Getting Started entry on docs: https://vite-plugin-pwa.netlify.app/guide/

userquin avatar Apr 21 '22 10:04 userquin

+1 for this feature. Tried using vite-plugin-favicons-inject to generate my favicons, but this uses the library favicons and that autogenerates a manifest as well. They have no way to disable manifest generation (open issue for 3 years) and in my case that one is the one the browser always chose to load.

joezappie avatar Nov 22 '22 03:11 joezappie

Implemented in https://github.com/vite-pwa/vite-plugin-pwa/pull/621?

jacekkarczmarczyk avatar Mar 23 '24 01:03 jacekkarczmarczyk

Implemented in https://github.com/vite-pwa/vite-plugin-pwa/pull/621?

Yes, check ~~pwa-assets~~ assets-generator example (only when configuring the pwa assets to be generated on the fly via new pwaAssets option): theme-color will be also injected, check the docs https://vite-pwa-org.netlify.app/assets-generator/integrations.html

I'll try to add support to inject theme-color, favicon, and maskable icons to the html head using the manifest without pwaAssets configured (apple icons cannot be injected since the manifest doesn't have those icons).

userquin avatar Mar 23 '24 02:03 userquin

In fact this issue should be closed, I forgot to close it when PR merged.

userquin avatar Mar 23 '24 02:03 userquin