-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathsvgo.config-base.js
53 lines (51 loc) · 1.38 KB
/
svgo.config-base.js
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
47
48
49
50
51
52
53
const addClassNamesPlugin = require('./add_classnames.svgo-plugin');
module.exports = {
plugins: [
{
name: 'preset-default',
params: {
overrides: {
removeViewBox: false
}
}
},
{
name: 'addClassNamesPlugin',
type: 'perItem',
params: {
rules: [
{
attribute: 'fill',
value: '#222', // #222222 value in the svg gets shortened previously in the build, which requires the shortened value here as well
className: 'fi-icon-base-fill'
},
{
attribute: 'stroke',
value: '#222',
className: 'fi-icon-base-stroke'
}
]
},
fn: function (item, params) {
var patternMap = params.rules.map(function (rule) {
return {
pattern: [
new RegExp(['^', rule.attribute, '$'].join(''), 'i'),
new RegExp(['^', rule.value, '$'].join(''), 'i')
],
className: rule.className
};
});
patternMap.forEach(function (pm) {
if (item.attrs) {
for (const [name, value] of Object.entries(item.attrs)) {
if (pm.pattern[0].test(name) && pm.pattern[1].test(value.value)) {
item.class.add(pm.className);
}
}
}
});
}
}
]
};