-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathplugin.favicons.js
More file actions
46 lines (42 loc) · 1.6 KB
/
plugin.favicons.js
File metadata and controls
46 lines (42 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
const fs = require('node:fs');
const deepMerge = require('lodash.merge');
const ImageSize = require('image-size');
const FaviconsWebpackPlugin = require('favicons-webpack-plugin');
const APP = require('./app.config');
const DEFAULT_OPTIONS = {
mode: 'webapp',
devMode: 'webapp',
logo: './.favicons-source.svg',
publicPath: '/',
outputPath: 'img/favicons/',
prefix: 'img/favicons/',
favicons: {
lang: APP.LANGUAGE,
appShortName: APP.SHORT_NAME,
appDescription: APP.DESCRIPTION,
start_url: APP.START_URL,
background: APP.BACKGROUND_COLOR,
theme_color: APP.THEME_COLOR,
manifestRelativePaths: true,
icons: {
favicons: ['favicon-16x16.png', 'favicon-32x32.png', 'favicon-48x48.png', 'favicon.ico', 'favicon.svg'],
appleStartup: false,
windows: false,
yandex: false,
},
files: {
android: { manifestFileName: 'manifest.json' },
},
},
};
module.exports.FavIcon = function FavIcon(options) {
const mergedOptions = deepMerge({}, DEFAULT_OPTIONS, options);
const logoSize = ImageSize.imageSize(fs.readFileSync(mergedOptions.logo));
if (!(logoSize && logoSize.type === 'svg')) {
throw new Error(`FavIcon '${mergedOptions.logo}': the file is not a valid image (allowed only svg).`);
}
if (!(logoSize.width === 64 && logoSize.height === 64)) {
throw new Error(`FavIcon '${mergedOptions.logo}': image size (${logoSize.width}x${logoSize.height}) is not than (64x64).`);
}
return new FaviconsWebpackPlugin(mergedOptions);
};