Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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