Skip to content

ryoppippi/vite-plugin-favicons

Folders and files

NameName
Last commit message
Last commit date
Mar 18, 2025
Apr 17, 2025
Oct 9, 2024
Aug 26, 2024
Aug 26, 2024
Sep 20, 2024
Aug 26, 2024
Aug 30, 2024
Aug 26, 2024
Apr 13, 2025
Apr 17, 2025
Aug 26, 2024
Aug 26, 2024
Aug 26, 2024

Repository files navigation

vite-plugin-favicons 🎨

npm version npm downloads

Generate favicons for your Vite project with ease!

πŸš€ Features

  • Automatically generates favicons for your Vite project
  • Supports various favicon formats and sizes
  • Easy integration with Vite build process
  • Caching mechanism for faster builds
  • TypeScript support

πŸ“¦ Installation

npm install vite-plugin-favicons --save-dev
# or
yarn add vite-plugin-favicons --dev
# or
pnpm add vite-plugin-favicons -D

πŸ› οΈ Usage

  1. Import the plugin in your Vite config file:
import { defineConfig } from 'vite';
import { faviconsPlugin } from 'vite-plugin-favicons';

export default defineConfig({
	plugins: [
		faviconsPlugin({
			imgSrc: './src/assets/favicon.png',
			// other options...
		}),
	],
});

You must pass options defined in index.d.ts to the plugin. You can also pass options from the Favicons package.

  1. Use the generated favicons in your HTML:
import faviconLinks from 'virtual:favicons';

// You can see the output result
console.log(faviconLinks);

πŸ–ΌοΈ Svelte Example

Import the FaviconsHead component from the virtual:favicons module, and add it inside <svelte:head> tag in your Svelte component.

<script>
	import { FaviconsHead } from 'virtual:favicons';
</script>

<svelte:head>
	<!-- eslint-disable-next-line svelte/no-at-html-tags -->
	{@html FaviconsHead}
</svelte:head>

Then use this component to inject the favicon links into the head tag in your Svelte app.

You can see SvelteKit Example Project.

πŸ”„ Usage in Other Frameworks

While the example above is Svelte-specific, you can use this plugin with any framework that works with Vite. The key is to import the favicon links from virtual:favicons and insert them into your HTML head section using the appropriate method for your framework.

βš™οΈ Configuration

The plugin accepts the following options:

  • imgSrc (required): Path to the source image for generating favicons
  • faviconAssetsDest (optional): Output path for favicon images and manifest (default: ${assetsDir}/favicons)
  • Other options from the Favicons package

The additional options are based on the Favicons library. For a full list of options and their descriptions, please refer to the Favicons package documentation.

🧩 TypeScript Support

This plugin includes TypeScript definitions. You can import types as follows:

import type { Options } from 'vite-plugin-favicons';

πŸ”„ Caching

The plugin implements a caching mechanism to avoid regenerating favicons unnecessarily. It uses an MD5 hash of the configuration and source image to determine if regeneration is needed.

🀝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

πŸ“„ License

This project is licensed under the MIT License.

πŸ™ Acknowledgements

This plugin is built on top of the excellent Favicons package.

πŸ“ Related Projects