-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsvgo.config.cjs
51 lines (51 loc) · 1.11 KB
/
svgo.config.cjs
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
module.exports = {
multipass: true,
js2svg: {
indent: 0,
pretty: false,
},
plugins: [
// First, add classes to black and white icons
{
name: 'addClassesToSVGElement',
params: {
className: 'bw-icon',
},
fn: (_ast, params, info) => {
// Apply only to files with the .bw.svg suffix
return info.path.endsWith('.bw.svg') ? { ...params } : null;
},
},
// Then apply standard optimizations
{
name: 'preset-default',
params: {
overrides: {
removeViewBox: false,
removeUnknownsAndDefaults: {
keepRoleAttr: true,
},
},
},
},
// Separately configure removeAttrs
{
name: 'removeAttrs',
params: {
attrs: ['class:!/^bw-icon$/'],
},
fn: (ast, params, info) => {
if (info.path.endsWith('.bw.svg')) {
params.attrs.push('fill', 'stroke', 'stroke-width', 'stroke-opacity');
}
return null; // null means "use the plugin's default behavior"
},
},
// Finally, remove unnecessary spaces and optimize styles
'removeEmptyAttrs',
'removeEmptyText',
'removeEmptyContainers',
'minifyStyles',
'convertStyleToAttrs',
],
};