1.3.8 • Published 2 years ago

webpack-favicons v1.3.8

Weekly downloads
69
License
MIT
Repository
github
Last release
2 years ago

Build Status Minimum node.js version downloads version GitLab release MIT License Maintenance

Does this plugin work with Webpack 4?

No, you should checkout https://github.com/jantimon/favicons-webpack-plugin for a Webpack 4 compatible plugin.

How does it works

By tapping into the Webpack 5's latest hooks, WebackFavicon digs into a given build to search for any instances of HTML file assets. While doing that, it leverages the favicon (https://github.com/itgalaxy/favicons) module to generate configured favicons off your provided source file.

Once done, you will have device or browser specific generated favicons written to disk while HTML files (with a <head> tag) will have corresponding <link> tags injected.

Does this work with CopyWebpackPlugin?

Yep! While it is more common to see a Webpack configuration using HtmlWebpackPlugin in order to process HTML files; WebpackFavicons will inject <link> tags into HTML documents found being copied by CopyWebpackPlugin and/or HtmlWebpackPlugin.


Install

npm i --save-dev webpack-favicons

or

yarn add --dev webpack-favicons

Webpack Config

const WebpackFavicons = require('webpack-favicons');

Instantiate a new WebpackFavicons() class within Webpack configuration's plugin array:

// Basic configuration

module.exports = {
  output: {
    path: '/dist', 
    publicPath: '/~media/'
  }  
  plugins: [
    new WebpackFavicons({
      src: 'assets/favicon.svg',
      path: 'img',
      background: '#000',
      theme_color: '#000',
      icons: {
        favicons: true
      }
    })
  ]
};

Will result in file(s) being written to:

  • /dist/img/favicon.ico
  • /dist/img/favicon16x16.png
  • /dist/img/favicon32x32.png
  • /dist/img/favicon48x48.png

While any HTML with a <head> tag will have paths to favicons added:

<link rel="shortcut icon" href="/~media/img/favicon.ico">
<link rel="icon" type="image/png" sizes="16x16" href="/~media/img/favicon-16x16.png">
<link rel="icon" type="image/png" sizes="32x32" href="/~media/img/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="48x48" href="/~media/img/favicon-48x48.png">

It is recommended that your source favicon file be a SVG vector file to allow best possible quality to generated pixel based favicons from.


Options

Note: These options both come from, and are directly passed to the favicon generating node module. For much more information about these options please visit: https://github.com/itgalaxy/favicons

OptionTypeDescription
srcStringPath to the source favicon file which all favicons will be generated from
pathStringPath to where icons get written (is relative to webpack's output.path)
appNameStringYour application's name.
appShortNameStringYour application's short_name. (Optional. If not set, appName will be used)
appDescriptionStringYour application's description.
developerNameStringYour (or your developer's) name.
developerURLStringYour (or your developer's) URL.
dirStringPrimary text direction for name, short_name, and description
langStringPrimary language for name and short_name
backgroundStringBackground color for flattened icons.
theme_colorStringTheme color user for example in Android's task switcher.
appleStatusBarStyleStringStyle for Apple status bar: "black-translucent", "default", "black".
displayStringPreferred display mode: "fullscreen", "standalone", "minimal-ui" or "browser".
orientationStringDefault orientation: "any", "natural", "portrait" or "landscape".
scopeStringset of URLs that the browser considers within your app
start_urlStringStart URL when launching the application from a device.
versionStringYour application's version string.
loggingBooleanPrint logs to console?
pixel_artStringKeeps pixels "sharp" when scaling up, for pixel art. Only supported in offline mode.
loadManifestWithCredentialsBooleanBrowsers don't send cookies when fetching a manifest, enable this to fix that.
iconsObjectSee below for more details about this object's options.

Icon Object's Options

OptionTypeDescription
androidBooleanCreate Android homescreen icon. boolean or { offset, background, mask, overlayGlow, overlayShadow } or an array of sources
appleIconBooleanCreate Apple touch icons. boolean or { offset, background, mask, overlayGlow, overlayShadow } or an array of sources
appleStartupBooleanCreate Apple startup images. boolean or { offset, background, mask, overlayGlow, overlayShadow } or an array of sources
coastBooleanCreate Opera Coast icon. boolean or { offset, background, mask, overlayGlow, overlayShadow } or an array of sources
faviconsBooleanCreate regular favicons. boolean or { offset, background, mask, overlayGlow, overlayShadow } or an array of sources
firefoxBooleanCreate Firefox OS icons. boolean or { offset, background, mask, overlayGlow, overlayShadow } or an array of sources
windowsBooleanCreate Windows 8 tile icons. boolean or { offset, background, mask, overlayGlow, overlayShadow } or an array of sources
yandexBooleanCreate Yandex browser icon. boolean or { offset, background, mask, overlayGlow, overlayShadow } or an array of sources

Callback

Optional callback allowing the opportunity to alter the generated images, html and manifest file(s) data prior to Webpack writing anything to disk:

// Basic configuration

module.exports = {
  output: {
    path: '/dist', 
    publicPath: '/~media/'
  }  
  plugins: [
    new WebpackFavicons({
      ...
    }, (response) => {
      // alter generated images, html or manifest file data here
      response.images[0].name = 'custom.ico';
      response.html[0] = response.html[0].replace('favicon.ico', 'custom.ico');
    })
  ]
};

Tests

Webpack Favicons comes with a few tests. These helps ensure that both favicons get written to disk and that link tags are injected into any HTML assets within the larger Webpack build process.

Simply run npm run test or yarn test from the root of the plugin to run test.

Running a test will produce a /dist/ directory.

If you would like to change a test, update the root package.json file's test script to use any of the /test/test.config.js files.

1.2.0

2 years ago

1.0.8

2 years ago

1.3.4

2 years ago

1.2.5

2 years ago

1.3.2

2 years ago

1.3.0

2 years ago

1.3.8

2 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago