-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsvgo.config.js
More file actions
57 lines (56 loc) · 1.42 KB
/
svgo.config.js
File metadata and controls
57 lines (56 loc) · 1.42 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
47
48
49
50
51
52
53
54
55
56
57
const flattenGroups = {
name: 'flattenGroups',
fn: () => ({
element: {
exit: (node, parentNode) => {
if (node.name !== 'g') return;
const groupAttrs = node.attributes ?? {};
for (const child of node.children) {
if (child.type !== 'element') continue;
child.attributes ??= {};
for (const [key, value] of Object.entries(groupAttrs)) {
if (key === 'opacity' && child.attributes.opacity != null) {
child.attributes.opacity = String(
Number(child.attributes.opacity) * Number(value)
);
} else if (child.attributes[key] == null) {
child.attributes[key] = value;
}
}
}
const idx = parentNode.children.indexOf(node);
parentNode.children.splice(idx, 1, ...node.children);
},
},
}),
};
export const SVGOConfig = {
plugins: [
{
name: 'preset-default',
params: {
overrides: {
convertTransform: false,
inlineStyles: false,
},
},
},
// Keep viewBox
'removeViewBox',
// convert width/height to viewBox if missing
{ name: 'removeDimensions' },
flattenGroups,
{
name: 'removeAttrs',
params: {
attrs: [
'path:fill',
'circle:fill',
'rect:fill',
'polygon:fill',
'line:stroke',
],
},
},
],
};