Skip to content

Instantly share code, notes, and snippets.

@crisu83
Created December 8, 2020 09:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save crisu83/825c645949f454a02c16027d4ea45287 to your computer and use it in GitHub Desktop.
Save crisu83/825c645949f454a02c16027d4ea45287 to your computer and use it in GitHub Desktop.
Script for generating favicons from an image file.
// eslint-disable-next-line node/no-unpublished-import
import favicons from 'favicons';
import fs from 'fs';
const [, , source] = process.argv;
if (!source) {
throw new Error('You need to specify a `source`.');
}
const config = {
appName: 'My app',
background: '#fff',
icons: {
appleStartup: false,
coast: false,
firefox: false,
windows: false,
yandex: false,
},
themeColor: '#bada55', // Get it? :D
};
const skipRegexp = new RegExp(
[
'favicon.ico',
'favicon-(?!.*32x32).*.png',
'android-chrome-(?!.*192x192).*.png',
'apple-touch-icon.png',
'apple-touch-icon-(?!.*180x180).*.png',
].join('|')
);
favicons(source, config, (error, response) => {
if (error) {
console.log(error.message);
return;
}
response.images.forEach(image => {
if (!skipRegexp.test(image.name)) {
fs.writeFileSync(
`${process.cwd()}/public/favicons/${image.name}`,
image.contents
);
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment