Set up
// vite.config.js
import { defineConfig } from 'vite'
import favseed from 'favseed/vite'
export default defineConfig({
plugins: [favseed({ input: 'src/logo.svg' })],
})
In dev
vite dev builds the icons the first time a page asks for one, then serves them from memory. Edit the logo or favseed.config.* and the icons rebuild and the page reloads.
Dev builds use effort: 'fast', so their PNG and ICO bytes differ from the build’s.
In a build
vite build writes the release icons to the output directory, next to index.html. favseed never writes to public/.
The head tags
favseed adds its <link> tags to index.html, unless the page already has a <link rel="icon">. A framework without an index.html can import them instead:
import { links, files } from 'virtual:favseed'
links is the <link> block as a string, and files lists every generated file as { name, href, type }. For TypeScript, add "favseed/vite/client" to compilerOptions.types, as with Vite’s own vite/client.
Options
The plugin takes the same options as favseed.config.*, except out: Vite decides the output directory. Options passed to the plugin win over the config file. base defaults to Vite’s base.
Files in public/
Your files come first. If public/ already holds a file favseed would write, such as favicon.ico, with different bytes, vite build stops with an error and vite dev serves your file with a warning. Delete it to use favseed’s.
With vite-plugin-pwa
vite-plugin-pwa writes its own manifest, so favseed does not write one. Pass favseed’s icons to it:
import { defineConfig } from 'vite'
import { VitePWA } from 'vite-plugin-pwa'
import favseed, { favseedIcons } from 'favseed/vite'
export default defineConfig({
plugins: [
favseed(),
VitePWA({ manifest: { name: 'Example', icons: favseedIcons() } }),
],
})
Give favseedIcons() the same sizes, bg and base as the plugin. Turn off vite-plugin-pwa’s pwaAssets option: it writes a favicon.ico of its own, and favseed warns when both are on.