Let webpack generate all your favicons and icons for you
npx @tessl/cli install tessl/npm-favicons-webpack-plugin@6.0.0Favicons Webpack Plugin is a webpack plugin that automatically generates comprehensive favicon and icon collections for web applications. It creates 44 different icon formats suitable for iOS devices, Android devices, Windows Phone, and various desktop browsers from a single source logo image (PNG or SVG), along with webapp manifest files and appropriate meta tags.
npm install --save-dev favicons favicons-webpack-pluginconst FaviconsWebpackPlugin = require('favicons-webpack-plugin');For ES modules:
import FaviconsWebpackPlugin from 'favicons-webpack-plugin';const FaviconsWebpackPlugin = require('favicons-webpack-plugin');
// Zero-config usage (looks for logo.png in webpack context)
module.exports = {
plugins: [
new FaviconsWebpackPlugin()
]
};
// Basic usage with logo path
module.exports = {
plugins: [
new FaviconsWebpackPlugin('/path/to/logo.png') // SVG works too!
]
};
// Advanced usage with configuration options
module.exports = {
plugins: [
new FaviconsWebpackPlugin({
logo: './src/logo.png',
cache: true,
inject: true,
favicons: {
appName: 'My App',
appDescription: 'My awesome application',
developerName: 'Developer Name',
background: '#fff',
theme_color: '#333'
}
})
]
};The plugin integrates with webpack's compilation process through several key components:
FaviconsWebpackPlugin provides the webpack plugin interfaceCreates a new instance of the favicons webpack plugin.
/**
* Creates a new favicons webpack plugin instance
* @param {FaviconWebpackPlugionOptions | string} [args] - Configuration options or logo path (optional for zero-config)
* @returns {FaviconsWebpackPlugin} New plugin instance
*/
constructor(args?: FaviconWebpackPlugionOptions | string): FaviconsWebpackPlugin;Usage Examples:
// String parameter (logo path only)
new FaviconsWebpackPlugin('/path/to/logo.png');
// Configuration object
new FaviconsWebpackPlugin({
logo: './src/logo.svg',
cache: true,
inject: true,
favicons: {
appName: 'My App',
background: '#ffffff'
}
});
// Zero-config (looks for logo.png in webpack context)
new FaviconsWebpackPlugin();Standard webpack plugin apply method that hooks into the webpack compilation process.
/**
* Webpack plugin apply method
* @param {import('webpack').Compiler} compiler - Webpack compiler instance
*/
apply(compiler: import('webpack').Compiler): void;Complete configuration interface for customizing favicon generation behavior.
interface FaviconWebpackPlugionOptions {
/** Source logo path(s) - can be PNG or SVG (optional for zero-config, automatically looks for logo.png in webpack context) */
logo?: string | string[];
/** Maskable source logo path(s) - can be PNG or SVG (optional) */
logoMaskable?: string | string[];
/**
* Enable caching (default: true)
* Note: disabling caching may increase build times considerably
*/
cache?: boolean;
/**
* Inject HTML links/metadata (default: true)
* Requires html-webpack-plugin for injection
* - boolean: true/false to enable/disable injection
* - function: predicate that takes html-webpack-plugin instance and returns boolean
*/
inject?: boolean | ((htmlWebpackPlugin: any) => boolean);
/** Favicons library configuration options */
favicons?: Partial<import('favicons').FaviconOptions>;
/**
* Favicon generation mode (default: 'auto')
* - 'light': Fast compilation, limited features (single favicon)
* - 'webapp': Full generation, wide browser support (44 formats)
* - 'auto': Light for development, webapp for production
*/
mode?: 'light' | 'webapp' | 'auto';
/**
* Development mode override
* - 'light': Fast compilation for development
* - 'webapp': Full generation even in development
*/
devMode?: 'light' | 'webapp';
/**
* Web app manifest configuration
* Can be a file path to base manifest or manifest object
*/
manifest?: string | { [key: string]: any };
/** Prefix path for generated assets (default: 'assets/') */
prefix?: string;
/**
* Output directory relative to webpack output dir
* If not set, prefix is used
*/
outputPath?: string;
/** Override webpack's publicPath for favicon assets */
publicPath?: string;
}Complete configuration options for the underlying favicons library (v7.0.1+):
interface FaviconOptions {
/** Application name (defaults to package.json name) */
appName?: string;
/** Application description (defaults to package.json description) */
appDescription?: string;
/** Application short name for mobile devices */
appShortName?: string;
/** Application version (defaults to package.json version) */
version?: string;
/** Developer name (defaults to package.json author.name) */
developerName?: string;
/** Developer URL (defaults to package.json author.url) */
developerURL?: string;
/** Language code for the application */
lang?: string;
/** Background color for icons and splash screens */
background?: string;
/** Theme color for browser UI */
theme_color?: string;
/** Apple mobile web app status bar style */
appleStatusBarStyle?: 'default' | 'black' | 'black-translucent';
/** Display mode for PWA */
display?: 'standalone' | 'fullscreen' | 'minimal-ui' | 'browser';
/** Orientation constraint for PWA */
orientation?: 'portrait' | 'landscape' | 'any' | 'natural' | 'portrait-primary' | 'portrait-secondary' | 'landscape-primary' | 'landscape-secondary';
/** Scope of the PWA */
scope?: string;
/** Start URL for the PWA */
start_url?: string;
/** Preferred related applications */
preferRelatedApplications?: boolean;
/** Related applications list */
relatedApplications?: Array<{
platform: string;
url?: string;
id?: string;
}>;
/** Path prefix for generated assets (not needed when using webpack plugin) */
path?: string;
/** Logging configuration */
logging?: boolean;
/** Pixel art scaling method */
pixel_art?: boolean;
/** Load manifest from file */
loadManifestWithCredentials?: boolean;
/** Icon generation options - control which icon types to generate */
icons?: {
/** Android homescreen icon */
android?: boolean | AndroidIconOptions;
/** Apple touch icon */
appleIcon?: boolean | AppleIconOptions;
/** Apple startup images */
appleStartup?: boolean | AppleStartupOptions;
/** Opera Coast icon */
coast?: boolean | CoastIconOptions;
/** Standard favicons */
favicons?: boolean | FaviconsOptions;
/** Firefox OS icons */
firefox?: boolean | FirefoxIconOptions;
/** Windows tile icons */
windows?: boolean | WindowsIconOptions;
/** Yandex browser icon */
yandex?: boolean | YandexIconOptions;
};
}
interface AndroidIconOptions {
/** Generate Android adaptive icons */
adaptive?: boolean;
/** Offset for adaptive icons */
offset?: number;
/** Background color for adaptive icons */
background?: boolean | string;
/** Mask for adaptive icons */
mask?: boolean;
/** Shadow for icons */
shadow?: boolean;
}
interface AppleIconOptions {
/** Generate different sized icons */
sizes?: number[];
/** Offset for icons */
offset?: number;
/** Background color */
background?: boolean | string;
}
interface AppleStartupOptions {
/** Generate startup images */
background?: boolean | string;
/** Offset for startup images */
offset?: number;
}
interface CoastIconOptions {
/** Offset for Coast icon */
offset?: number;
/** Background color */
background?: boolean | string;
}
interface FaviconsOptions {
/** Standard favicon sizes to generate */
sizes?: number[];
}
interface FirefoxIconOptions {
/** Firefox manifest background */
background?: boolean | string;
/** Offset for Firefox icons */
offset?: number;
}
interface WindowsIconOptions {
/** Background color for Windows tiles */
background?: boolean | string;
/** Offset for Windows tiles */
offset?: number;
}
interface YandexIconOptions {
/** Background color for Yandex icon */
background?: boolean | string;
/** Offset for Yandex icon */
offset?: number;
}The simplest setup - place a logo.png file in your webpack context directory:
const FaviconsWebpackPlugin = require('favicons-webpack-plugin');
module.exports = {
plugins: [
new FaviconsWebpackPlugin() // Automatically finds logo.png
]
};Different modes for optimal development experience:
const FaviconsWebpackPlugin = require('favicons-webpack-plugin');
module.exports = {
plugins: [
new FaviconsWebpackPlugin({
logo: './src/logo.png',
mode: 'auto', // Light mode in dev, webapp mode in prod
// Or explicitly set development mode:
devMode: 'light' // Fast builds during development
})
]
};Complete Progressive Web App setup with manifest:
const FaviconsWebpackPlugin = require('favicons-webpack-plugin');
module.exports = {
plugins: [
new FaviconsWebpackPlugin({
logo: './src/logo.png',
favicons: {
appName: 'My PWA App',
appDescription: 'A Progressive Web Application',
developerName: 'My Company',
developerURL: 'https://mycompany.com',
background: '#ffffff',
theme_color: '#000000',
display: 'standalone',
orientation: 'portrait'
},
manifest: './src/manifest.webmanifest' // Base manifest file
})
]
};Control where favicon assets are generated:
const FaviconsWebpackPlugin = require('favicons-webpack-plugin');
module.exports = {
plugins: [
new FaviconsWebpackPlugin({
logo: './src/logo.png',
prefix: 'icons/', // Default asset prefix
outputPath: '../public/icons', // Custom output directory
publicPath: '/static/icons/' // Custom public path
})
]
};Control when HTML meta tags are injected:
const FaviconsWebpackPlugin = require('favicons-webpack-plugin');
module.exports = {
plugins: [
new FaviconsWebpackPlugin({
logo: './src/logo.png',
inject: (htmlPlugin) => {
// Only inject for specific HTML files
return htmlPlugin.options.filename === 'index.html';
}
})
]
};Use multiple source images for comprehensive icon generation:
const FaviconsWebpackPlugin = require('favicons-webpack-plugin');
module.exports = {
plugins: [
new FaviconsWebpackPlugin({
logo: [
'./src/logo.png',
'./src/logo.svg'
],
logoMaskable: './src/logo-maskable.png' // For Android adaptive icons
})
]
};The plugin generates various types of assets depending on the mode:
favicon.png or favicon.svg (single favicon)manifest.webmanifest (if manifest options provided)When used with html-webpack-plugin, the plugin automatically injects appropriate HTML meta tags:
<link rel="apple-touch-icon" sizes="180x180" href="/assets/apple-touch-icon-180x180.png">
<link rel="icon" type="image/png" sizes="32x32" href="/assets/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="/assets/favicon-16x16.png">
<link rel="manifest" href="/assets/manifest.webmanifest">
<meta name="theme-color" content="#ffffff">
<!-- ... and many more -->The plugin handles several error conditions: