• Stars
    star
    1,200
  • Rank 39,023 (Top 0.8 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 8 years ago
  • Updated 5 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Let webpack generate all your favicons and icons for you

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.

More Repositories

1

html-webpack-plugin

Simplifies creation of HTML files to serve your webpack bundles
JavaScript
10,686
star
2

html-webpack-harddisk-plugin

Write html files to hard disk even when using the webpack dev server or middleware
JavaScript
226
star
3

cpuprofile-webpack-plugin

Generate a cpuprofile for your webpack builds
TypeScript
153
star
4

next-yak

a streamlined CSS-in-JS solution tailor-made for Next.js, seamlessly combining the expressive power of styled-components syntax with efficient build-time extraction and minimal runtime footprint, ensuring optimal performance and easy integration with existing atomic CSS frameworks like Tailwind CSS
TypeScript
116
star
5

iconfont-webpack-plugin

Simple icon font handling for webpack
JavaScript
112
star
6

resource-hints-webpack-plugin

Adds automatically resource hints to your html-files
JavaScript
100
star
7

css-variable

Define CSSVariables in JS
JavaScript
89
star
8

text-box-trim-examples

text-box-trim examples and playground (previously known as leading-trim)
TypeScript
52
star
9

next-relay-demo

Relay React Concurrency Example
TypeScript
33
star
10

css-framework-performance

Compare different css approaches
TypeScript
30
star
11

extra-entry-webpack-plugin

Allows to add entry points with a defined output filename.
JavaScript
18
star
12

remote-web-worker

Cross origin web worker
TypeScript
15
star
13

chrome-profile-sourcemap-resolver

Apply sourcemaps for a recorded chrome profile
TypeScript
11
star
14

react-use-ref-effect

an useEffect hook optimized for useRef
TypeScript
10
star
15

storybook-puppeteer

`storybook-puppeteer` is a CLI to run end-to-end tests for storybook stories.
TypeScript
10
star
16

cpuprofile-to-flamegraph

Convert a nodejs .cpuprofile to a renderable flame graph node
TypeScript
10
star
17

svg-placeholder

A fast svg image mock placeholder service which can be used as a stand-alone-server or as a express-middleware
JavaScript
9
star
18

htl-template-loader

Webpack loader for HTL/Sightly data-sly-template templates
JavaScript
8
star
19

webpack-recompilation-simulator

Helper to test and measure webpack recompilations
JavaScript
8
star
20

next-swc-plugin-demo

basic swc wasm demo for nextjs
TypeScript
7
star
21

grunt-githash

Grunt plugin to get the current git hash, branch and tag
JavaScript
6
star
22

stylelint-safari-background-clip

Try to detect possible safari background clip bugs - https://bugs.webkit.org/show_bug.cgi?id=169125
JavaScript
6
star
23

requirejs-modernizr

Attemp to use requirejs with modernizr
JavaScript
6
star
24

css-sourcemaps-webpack-plugin

Simple CSS Sourcemap configuration for CSS, Less, Stylus and Sass
JavaScript
5
star
25

banner-loader

Webpack loader to prefix or postfix files
JavaScript
4
star
26

webpack-dependency-stats

Extracts a flat list of all dependencies and dependents of a given webpack module
JavaScript
4
star
27

postcss-inline

PostCSS plugin that puts fonts / and images as data URIs into your CSS
JavaScript
3
star
28

ariaMenu

Accessible menu with Aria support
JavaScript
3
star
29

handlebars-faker

Small helper to use faker inside your handlebars template
JavaScript
3
star
30

opentype-playground

Playground for openType.js and React
TypeScript
2
star
31

css-exclude

Allows to exclude css with anotations
JavaScript
2
star
32

hot-file-cache

A file cache for which will invalidate automatically if the source changes
JavaScript
2
star
33

mediaqueries-with-sass-modernizr

Example usage of sass with modenizr and media queries
JavaScript
2
star
34

zx-packed

A lightweight version of 🐚 zx
JavaScript
2
star
35

meteor-gpio

Getting and setting GPIO values for Raspberry Pi / Odroid / BeagleBone
JavaScript
2
star
36

auto-peer

An experimental webRTC library based on peer.js - for game and collaboration app prototyping
JavaScript
2
star
37

grunt-wizard

A wizard to select the desired task and options
JavaScript
2
star
38

sync-cpuprofiler

Create a new cpuprofile for the currend node process
JavaScript
1
star
39

layout-recalculate-detector

Experiment to measure layout recalculations during hydration
JavaScript
1
star
40

ng-directive-parser

Extracts angular directive information from source
JavaScript
1
star
41

drupal8-vagrant

Simple Drupal sandbox
Shell
1
star
42

yarn-plugin-leaf

Yarn plugin experiment
TypeScript
1
star
43

clean-commit-gui

Electron git interface
JavaScript
1
star
44

grunt-tpl-wrap

A grunt plugin to wrap file contents with a tpl template
JavaScript
1
star
45

handlebars-to-ecmascript

Convert handlebars to an ecmascript AST
JavaScript
1
star
46

useWorkerPromise

extrem lightweight WebWorker react integration
TypeScript
1
star
47

https-to-http-proxy

Allows to access an insecure HTTPS page over http
JavaScript
1
star
48

terrific-singleton

helper module to use terrific in react projects - still alpha - don't use
JavaScript
1
star