Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

emoji-favicon-webpack-plugin

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

emoji-favicon-webpack-plugin - npm Package Compare versions

Comparing version 1.0.1 to 1.1.1

webpack.config.js

11

package.json
{
"name": "emoji-favicon-webpack-plugin",
"version": "1.0.1",
"version": "1.1.1",
"description": "Let webpack generate an emoji favicon for you",

@@ -24,7 +24,12 @@ "author": "Trevor Blades <tdblades@gmail.com>",

"dependencies": {
"emoji-name-map": "^1.2.7",
"emoji-unicode": "^1.0.9",
"favicon-emoji": "^2.3.0",
"to-ico": "^1.1.5"
"pn": "^1.1.0",
"svg2png": "^4.1.1",
"to-ico": "^1.1.5",
"twemoji": "^11.2.0"
},
"devDependencies": {
"@trevorblades/eslint-config": "^6.17.0",
"@trevorblades/eslint-config": "^6.18.0",
"eslint": "^5.6.0",

@@ -31,0 +36,0 @@ "html-webpack-plugin": "^3.2.0",

const render = require('favicon-emoji/lib/render');
const toIco = require('to-ico');
const emojiUnicode = require('emoji-unicode');
const emojiNameMap = require('emoji-name-map');
const fs = require('pn/fs');
const svg2png = require('svg2png');
const isShortcode = /^:?[a-z0-9_]+:?$/;
async function generatePngs(options) {
let emoji = typeof options === 'string' ? options : options.emoji;
if (isShortcode.test(emoji)) {
emoji = emojiNameMap.get(emoji);
}
const sizes = options.sizes || [16, 32, 48];
if (options.useSystem) {
return await render(emoji, sizes);
}
const unicode = emojiUnicode(emoji);
const path = require.resolve(`twemoji/2/svg/${unicode}.svg`);
const svg = await fs.readFile(path);
return await Promise.all(
sizes.map(size =>
svg2png(svg, {
width: size,
height: size
})
)
);
}
class EmojiFaviconPlugin {
constructor(emoji) {
this.emoji = emoji;
constructor(options) {
this.options = options;
}

@@ -12,28 +41,35 @@

'EmojiFaviconPlugin',
(compilation, callback) =>
render(this.emoji, [16, 32, 48])
.then(toIco)
.then(ico => {
compilation.assets['favicon.ico'] = {
source: () => ico,
size: () => ico.length
};
async (compilation, callback) => {
const pngs = await generatePngs(this.options);
const ico = await toIco(pngs);
compilation.assets['favicon.ico'] = {
source: () => ico,
size: () => ico.length
};
if (compilation.hooks.htmlWebpackPluginBeforeHtmlProcessing) {
compilation.hooks.htmlWebpackPluginBeforeHtmlProcessing.tapAsync(
'EmojiFaviconPlugin',
(htmlPluginData, callback) => {
const publicPath = compilation.outputOptions.publicPath || '';
htmlPluginData.html = htmlPluginData.html.replace(
/(<\/head>)/i,
`<link rel="shortcut icon" href="${publicPath}favicon.ico">$&`
);
if (compilation.hooks.htmlWebpackPluginBeforeHtmlProcessing) {
compilation.hooks.htmlWebpackPluginBeforeHtmlProcessing.tapAsync(
'EmojiFaviconPlugin',
(htmlPluginData, callback) => {
const publicPath = compilation.outputOptions.publicPath || '';
htmlPluginData.html = htmlPluginData.html.replace(
/(<\/head>)/i,
`<link rel="shortcut icon" href="${publicPath}favicon.ico">$&`
);
callback(null, htmlPluginData);
}
);
callback(null, htmlPluginData);
}
);
}
callback();
})
callback();
// console.log(pngs);
// render(this.emoji, [16, 32, 48])
// .then(ico => {
// });
}
);

@@ -40,0 +76,0 @@ }

@@ -5,3 +5,3 @@ # Emoji Favicon Webpack Plugin

Leverages [favicon-emoji](https://github.com/albinekb/favicon-emoji) to generate an emoji favicon for your webapp
Generates a favicon based on an emoji for your webapp

@@ -38,8 +38,18 @@ ## Installation

## Caveats
### Options
MacOS has a pretty awesome and extensive library of emojis built into its [Apple Color Emoji](https://en.wikipedia.org/wiki/Apple_Color_Emoji) typeface, but other operating systems aren't so lucky. If you normally develop on a Mac, you will see different results when you build your app on a Linux or Windows machine.
By default, we use [Twemoji](https://github.com/twitter/twemoji) for consistent results across all operating systems. If you would prefer to use your system's emoji font instead, specify the `useSystem` option in the constructor. You can also choose which icon `sizes` to include!
In order to get consistent results between development and production, you should make sure that you use the same operating system for building in each environment. For example, if you're using Travis CI to build your app, you must specify `osx` as your `os` option in your build config. You can read more about using OS X in Travis [here](https://docs.travis-ci.com/user/reference/osx/).
```js
new EmojiFaviconPlugin({
emoji: '🍣',
useSystem: true,
sizes: [16] // default is [16, 32, 48]
})
```
> MacOS has a pretty awesome and extensive library of emojis built into its [Apple Color Emoji](https://en.wikipedia.org/wiki/Apple_Color_Emoji) typeface, but other operating systems aren't so lucky. If you normally develop on a Mac, you will see different results when you build your app on a Linux or Windows machine.
> In order to get consistent results between development and production, you should make sure that you use the same operating system for building in each environment. For example, if you're using Travis CI to build your app, you must specify `osx` as your `os` option in your build config. You can read more about using OS X in Travis [here](https://docs.travis-ci.com/user/reference/osx/).
## In the wild

@@ -46,0 +56,0 @@

/* eslint-env jest */
const EmojiFaviconPlugin = require('./plugin');
const HtmlPlugin = require('html-webpack-plugin');
const MemoryFileSystem = require('memory-fs');
const webpack = require('webpack');
const {JSDOM} = require('jsdom');
const config = require('./webpack.config.js');
const fs = new MemoryFileSystem();
const compiler = webpack({
entry: './index',
plugins: [new EmojiFaviconPlugin('🦑'), new HtmlPlugin()]
});
const compiler = webpack(config);
compiler.outputFileSystem = fs;

@@ -14,0 +10,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc