-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
configure-svgo.js
64 lines (59 loc) · 1.47 KB
/
configure-svgo.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
54
55
56
57
58
59
60
61
62
63
64
import path from 'path';
/**
* Docusaurus uses SVGR internally, which in turn uses SVGO. We need to
* configure SVGO to avoid issues with inlining multiple SVG documents into a
* single page.
*
* @returns {Object}
*
* @see https://github.com/facebook/docusaurus/issues/8297
*/
function configureSvgo() {
return {
name: 'configure-svgo',
configureWebpack(config) {
/** @type {object[]} */
const rules = config.module.rules;
const rule = rules.find((rule) => {
/** @type {string|undefined} */
const loader = rule.oneOf?.[0]?.use?.[0]?.loader;
return loader && loader.includes('/@svgr/');
});
const svgoConfig = rule.oneOf[0].use[0].options.svgoConfig;
svgoConfig.plugins = [
{
...svgoConfig.plugins[0],
params: {
overrides: {
...svgoConfig.plugins[0].params.overrides,
mergePaths: {
noSpaceAfterFlags: true
}
}
}
},
{
name: 'prefixIds',
params: {
delim: '',
prefix: (_, info) => path.parse(info.path).name
}
},
{
name: 'removeXlink',
params: {
includeLegacy: true
}
},
'removeXMLNS'
];
return {
mergeStrategy: {
'module.rules': 'replace'
},
module: { rules }
};
}
};
}
module.exports = configureSvgo;