Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

favicons-webpack-plugin

jantimon335.5kMIT6.0.1TypeScript support: included

Let webpack generate all your favicons and icons for you

webpack, plugin, html-webpack-plugin, webapp, pwa, manifest, favicon, icon, png, svg

readme

Favicons Webpack Plugin

npm version CI js-semistandard-style

Leverages on favicons to automatically generate your favicons for you.

Installation

Install the plugin and favicons with npm:

$ npm install --save-dev favicons favicons-webpack-plugin

Zero Config Usage

Add your base logo as logo.png file to you webpack context folder. (By default the context is the current working directory)

Add the plugin to your webpack config as follows:

const FaviconsWebpackPlugin = require('favicons-webpack-plugin')

plugins: [
  new FaviconsWebpackPlugin()
]

Basic Usage

Demo

Add the plugin to your webpack config as follows:

const FaviconsWebpackPlugin = require('favicons-webpack-plugin')

...

plugins: [
  new FaviconsWebpackPlugin('/path/to/logo.png') // svg works too!
]

The default configuration will automatically generate webapp manifest files along with 44 different icon formats as appropriate for iOS devices, Android devices, Windows Phone and various desktop browsers out of your single logo.png.

Tip: You might want to fine tune what vendors to support.

A Note on Path Resolution

Under the hood, Webpack resolves the path to logo according to the following rules:

  • If /path/to/logo is absolute, there is nothing to resolve and the path specified is used as is.

  • If ./path/to/logo is relative, it's resolved with respect to Webpack's context, which defaults to process.cwd().

  • If path/to/logo is neither explicitly relative nor absolute, Webpack attempts to resolve it according to resolve.modules, which defaults to modules: ["node_modules"].

HTML Injection

In combination with html-webpack-plugin it will also inject the necessary html for you:

<link rel="apple-touch-icon" sizes="57x57" href="/assets/apple-touch-icon-57x57.png">
<link rel="apple-touch-icon" sizes="60x60" href="/assets/apple-touch-icon-60x60.png">
<link rel="apple-touch-icon" sizes="72x72" href="/assets/apple-touch-icon-72x72.png">
<link rel="apple-touch-icon" sizes="76x76" href="/assets/apple-touch-icon-76x76.png">
<link rel="apple-touch-icon" sizes="114x114" href="/assets/apple-touch-icon-114x114.png">
<link rel="apple-touch-icon" sizes="120x120" href="/assets/apple-touch-icon-120x120.png">
<link rel="apple-touch-icon" sizes="144x144" href="/assets/apple-touch-icon-144x144.png">
<link rel="apple-touch-icon" sizes="152x152" href="/assets/apple-touch-icon-152x152.png">
<link rel="apple-touch-icon" sizes="167x167" href="/assets/apple-touch-icon-167x167.png">
<link rel="apple-touch-icon" sizes="180x180" href="/assets/apple-touch-icon-180x180.png">
<link rel="apple-touch-icon" sizes="1024x1024" href="/assets/apple-touch-icon-1024x1024.png">
<link rel="apple-touch-startup-image" media="(device-width: 320px) and (device-height: 480px) and (-webkit-device-pixel-ratio: 1)" href="/assets/apple-touch-startup-image-320x460.png">
<link rel="apple-touch-startup-image" media="(device-width: 320px) and (device-height: 480px) and (-webkit-device-pixel-ratio: 2)" href="/assets/apple-touch-startup-image-640x920.png">
<link rel="apple-touch-startup-image" media="(device-width: 320px) and (device-height: 568px) and (-webkit-device-pixel-ratio: 2)" href="/assets/apple-touch-startup-image-640x1096.png">
<link rel="apple-touch-startup-image" media="(device-width: 375px) and (device-height: 667px) and (-webkit-device-pixel-ratio: 2)" href="/assets/apple-touch-startup-image-750x1294.png">
<link rel="apple-touch-startup-image" media="(device-width: 414px) and (device-height: 736px) and (orientation: landscape) and (-webkit-device-pixel-ratio: 3)" href="/assets/apple-touch-startup-image-1182x2208.png">
<link rel="apple-touch-startup-image" media="(device-width: 414px) and (device-height: 736px) and (orientation: portrait) and (-webkit-device-pixel-ratio: 3)" href="/assets/apple-touch-startup-image-1242x2148.png">
<link rel="apple-touch-startup-image" media="(device-width: 768px) and (device-height: 1024px) and (orientation: landscape) and (-webkit-device-pixel-ratio: 1)" href="/assets/apple-touch-startup-image-748x1024.png">
<link rel="apple-touch-startup-image" media="(device-width: 768px) and (device-height: 1024px) and (orientation: landscape) and (-webkit-device-pixel-ratio: 2)" href="/assets/apple-touch-startup-image-1496x2048.png">
<link rel="apple-touch-startup-image" media="(device-width: 768px) and (device-height: 1024px) and (orientation: portrait) and (-webkit-device-pixel-ratio: 1)" href="/assets/apple-touch-startup-image-768x1004.png">
<link rel="apple-touch-startup-image" media="(device-width: 768px) and (device-height: 1024px) and (orientation: portrait) and (-webkit-device-pixel-ratio: 2)" href="/assets/apple-touch-startup-image-1536x2008.png">
<link rel="icon" type="image/png" sizes="16x16" href="/assets/favicon-16x16.png">
<link rel="icon" type="image/png" sizes="32x32" href="/assets/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="228x228" href="/assets/coast-228x228.png">
<link rel="manifest" href="/assets/manifest.webmanifest">
<link rel="shortcut icon" href="/assets/favicon.ico">
<link rel="yandex-tableau-widget" href="/assets/yandex-browser-manifest.json">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
<meta name="apple-mobile-web-app-title">
<meta name="application-name">
<meta name="mobile-web-app-capable" content="yes">
<meta name="msapplication-TileColor" content="#fff">
<meta name="msapplication-TileImage" content="/assets/mstile-144x144.png">
<meta name="msapplication-config" content="/assets/browserconfig.xml">
<meta name="theme-color" content="#fff">

https://github.com/jantimon/favicons-webpack-plugin/blob/master/test/fixtures/expected/html

Advanced Usage

plugins: [
  new FaviconsWebpackPlugin({
    // Your source logo (required)
    logo: './src/logo.png',
    // Your maskable source logo (optional)
    logoMaskable: './src/logo-maskable.png',
    // Allow caching the assets across webpack builds. By default this will use
    // webpack's cache configuration, but can be set to false to disable caching.
    // Note: disabling caching may increase build times considerably.
    // For more information, see: https://webpack.js.org/configuration/cache/
    cache: true,
    // Override the publicPath option usually read from webpack configuration
    publicPath: '/static',
    // The directory to output the assets relative to the webpack output dir.
    // Relative string paths are allowed here ie '../public/static'. If this
    // option is not set, `prefix` is used.
    outputPath: '/public/static',
    // Prefix path for generated assets
    prefix: 'assets/',
    // Inject html links/metadata (requires html-webpack-plugin).
    // This option accepts arguments of different types:
    //  * boolean
    //    `false`: disables injection
    //    `true`: enables injection if that is not disabled in html-webpack-plugin
    //  * function
    //    any predicate that takes an instance of html-webpack-plugin and returns either
    //    `true` or `false` to control the injection of html metadata for the html files
    //    generated by this instance.
    inject: true,

    // Favicons configuration options (see below)
    favicons: {
      ...
    }
  })
]

To fine tune what icons/metadata is generated, refer to favicons' documentation.

The options specified under favicons: are handed over as is to favicons, except that if appName, appDescription, version, developerName or developerURL are left undefined, they will be automatically inferred respectively from name, description, version, author.name and author.url as defined in the nearest package.json if available. To disable automatically retrieving metadata from package.json, simply set to null the properties you want to omit.

Examples

Basic

const FaviconsWebpackPlugin = require('favicons-webpack-plugin')

plugins: [
  new FaviconsWebpackPlugin({
    logo: './src/logo.png', // svg works too!
    mode: 'webapp', // optional can be 'webapp', 'light' or 'auto' - 'auto' by default
    devMode: 'webapp', // optional can be 'webapp' or 'light' - 'light' by default 
    favicons: {
      appName: 'my-app',
      appDescription: 'My awesome App',
      developerName: 'Me',
      developerURL: null, // prevent retrieving from the nearest package.json
      background: '#ddd',
      theme_color: '#333',
      icons: {
        coast: false,
        yandex: false
      }
    }
  })
]

To fine tune what icons/metadata is generated, refer to favicons' documentation.

Handling Multiple HTML Files

const FaviconsWebpackPlugin = require('favicons-webpack-plugin')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const { basename } = require('path')

...

plugins: [
    new HtmlWebpackPlugin({
        template: 'a.html.tmpl',
        filename: 'a.html',
    }),
    new HtmlWebpackPlugin({
        template: 'b.html.tmpl',
        filename: 'b.html',
    }),
    new FaviconsWebpackPlugin({
        logo: 'logo.svg',
        inject: htmlPlugin => 
          basename(htmlPlugin.options.filename) === 'a.html',
    }),
],

Compilation Modes

Modes allow you to choose a very fast simplified favicon compilation or a production ready favicon compilation

By default or if the favicons mode option is set to auto the favicon compilation depends on the webpack mode:
If the webpack mode is set to development the favicons mode will use a quick light favicons build.
If the webpack mode is set to production the favicons mode will use a full webapp favicons build.

This behaviour can be adjusted by setting the favicons mode and devMode options.

Custom manifests

The manifest options allows to overwrite values of the generated manifest.webmanifest with own values

const FaviconsWebpackPlugin = require('favicons-webpack-plugin')

plugins: [
  new FaviconsWebpackPlugin({
    logo: './src/logo.png',
    mode: 'webapp',
    manifest: './src/manifest.webmanifest'
  })
]

Compatibility

favicons-webpack-plugin 2.x is compatible with html-webpack-plugin 3.x
favicons-webpack-plugin 3.x - 4.x is compatible with html-webpack-plugin 4.x
favicons-webpack-plugin 5.x - 6.x is compatible with html-webpack-plugin 5.x

Changelog

Take a look at the CHANGELOG.md.

Contribution

You're free to contribute to this project by submitting issues and/or pull requests.

Please keep in mind that every change and new feature should be covered by tests.

License

This project is licensed under MIT.

changelog

Changelog

All notable changes to this project will be documented in this file. See standard-version for commit guidelines.

6.0.0 (2022-11-21)

  • update dependencies to their latest versions (#342)

6.0.0-alpha.2 (2022-10-26)

  • support string array in options.logo (#332)
  • support options.logoMaskable (#333)
  • update manifest file extension (#341)

6.0.0-alpha.1 (2022-10-02)

  • Upgrage favicons to v7.0.1
  • Upgrade all dependencies to their latest versions

5.0.2 (2021-02-23)

Bug Fixes

  • ignore empty tags generated by favicons (5f94f54), closes #260

5.0.1 (2021-02-04)

Bug Fixes

  • remove unused dependencies (f3c5b17)

5.0.0 (2021-02-03)

⚠ BREAKING CHANGES

  • file based cache will only work if you configure webpacks filesystem cache
  • favicons needs to be installed separately
  • drop webpack@4 support

Features

  • add manifest option (e2928c4)
  • add support for webpack 5 publicPath 'auto' and relative favicons (7293186)
  • generate custom manifest in light mode (db677fc)
  • turn favicons into a peer dependency (8141094)
  • use the processAssets webpack api to add assets (d15d92f)
  • use webpack 5 cache system and remove child compilation (c1dc12c)

Bug Fixes

  • add support for content hash for light and webapp mode (8d4cead)
  • add support for webpack@5 'auto' publicPath (30c0d35)
  • allow compiling multiple icon sets (03c3514)
  • extract the cache (17721f0)
  • prevent recompilations (af5897a)
  • resolve correct result if filesnapshot is out of date (98e27b5)
  • track the base manifest file only if specified (04ca36a)

4.2.0 (2020-07-27)

Features

  • turn favicon into a transitive dependency to allow using upstream bugfixes (eb11a83)

4.1.0 (2020-07-27)

Features

  • show current html-webpack-plugin version (6ef0ce4)

4.0.0 (2020-07-27)

⚠ BREAKING CHANGES

  • drop support for node 8

Features

Bug Fixes

  • remove duplicate test-entry in .travis.yml (8d59acf)

3.0.1 (2020-01-29)

Bug Fixes

  • provide a error message if the plugin is incompatible to the html-webpack-plugin (bb26179)

3.0.0 (2020-01-02)

⚠ BREAKING CHANGES

  • remove "force" inject option
  • drop support for Webpack v3 and html-webpack-plugin v3

Features

  • add support for html-webpack-plugin v4 (395fc09)

Bug Fixes

  • remove "force" inject option (15bab27)

2.1.0 (2019-12-31)

Features

2.0.0 (2019-12-28)

⚠ BREAKING CHANGES

  • an empty string public path will no longer fallback to a slash
  • drop support for node versions < 8 to be able to upgrade favicons

Features

  • allow setting public path to an empty string (b3a5eb3)

Bug Fixes

  • remove unused contentHash (b48697f)
  • upgrade to new favicons version (7c86a6c)

1.0.2 (2019-09-06)

Bug Fixes

  • fix output path of dev favicon (b2b8fc7), closes #164

1.0.1 (2019-08-16)

Bug Fixes

  • fix hash generation for light-mode (67a8850), closes #159

1.0.0 (2019-08-14)

⚠ BREAKING CHANGES

  • Require Node 6 is or newer
  • align with webpack 4 and drop support for node < 6 (e41a990)
  • prefixes are always treated as a directory path
  • remove -[hash] from default prefix
  • by default only a subset of icons is generated in development

Bug Fixes

  • always treat prefix as a directory path (17aabba)
  • avoid failing if html-webpack-plugin isn't installed (1c0ee82)
  • broken links in content meta tags and browserconfig.xml (51bd1f8)
  • do not interpolate empty prefix (9e197f1)
  • do not rely on html-webpack-plugin's internals (9f166a7)
  • handle author as object in package.json (06da1f8)
  • invalidate cache when changing publicPath (29c9902)
  • set SingleEntryPlugin name (15c4a1a)
  • workaround issues with libxml (d23aea5)
  • update favicons to version 5.0.0 (3737fa3)

Features

  • add inject force option to overrule the html-webpack-plugin favicon option (73b51a1)
  • add light mode during development (47986be)
  • add support for html-webpack-plugin 4.x (94ead15)
  • add support for Webpack 4 (9db88ee)
  • add zero-config mode (793a840)
  • added compatibility for new webpack 4 .hooks mode (5ab0bb8)
  • allow skipping specific instances of html-webpack-plugin (d554946)
  • allow to specify a custom output paths (0755161)
  • cache assets using cache-loader (f2758ca)
  • change the default output prefix to assets (99a7310)
  • expose all options of the favicons npm package (ca4b6e9)
  • give the user more options to specifiy where to inject html (c8a4767)
  • make cache directory configurable (43a5aef)
  • remove -[hash] from default prefix (fc0eb3e)
  • the generated [hash] now is based on the current favicon-webpack-plugin version (ccfea37)

0.0.9

  • Improve support for Webpack 4

0.0.8

  • Add support for Webpack 4

0.0.7

  • Inject generated HTML to end of head

0.0.6

  • Add support for devtool: 'eval'

0.0.5

  • Invalidate cache on plugin version change

0.0.4

  • Add persistent caching to generate the favicons only once

0.0.3

  • Rename filename option to statsFilename
  • Add emitStats option (set to false by default)

BREAKING CHANGE

  • the stats file isn't generated by default anymore

0.0.2

  • Fix typos

0.0.1

  • Initial release