@@ -9,6 +9,57 @@ const util = require("util");
9
9
const webpack = require ( "webpack" ) ;
10
10
const execAsync = util . promisify ( require ( "child_process" ) . exec ) ;
11
11
12
+ /**
13
+ * Modify the svgo configuration (in place) to prevent it from minifying IDs in SVGs
14
+ *
15
+ * Refs:
16
+ * - https://github.com/facebook/docusaurus/issues/8297
17
+ * - https://github.com/svg/svgo/issues/1714
18
+ * - https://linear.app/foxglove/issue/FG-7251/logos-are-cut-off-on-mcapdev
19
+ *
20
+ * @param {webpack.Configuration } config
21
+ */
22
+ function modifySvgoConfig ( config ) {
23
+ const NEW_SVGO_CONFIG = {
24
+ plugins : [
25
+ {
26
+ name : "preset-default" ,
27
+ params : {
28
+ overrides : {
29
+ removeTitle : false ,
30
+ removeViewBox : false ,
31
+ cleanupIDs : false , // do not change IDs
32
+ } ,
33
+ } ,
34
+ } ,
35
+ ] ,
36
+ } ;
37
+ // find the svgo config rule and replace it
38
+ if ( config . module ?. rules instanceof Array ) {
39
+ for ( const rule of config . module . rules ) {
40
+ if ( typeof rule === "object" && rule . test ?. toString ( ) === "/\\.svg$/i" ) {
41
+ if ( rule . oneOf instanceof Array ) {
42
+ for ( const nestedRule of rule . oneOf ) {
43
+ if ( nestedRule . use instanceof Array ) {
44
+ for ( const loader of nestedRule . use ) {
45
+ if (
46
+ typeof loader === "object" &&
47
+ /* cspell:disable */
48
+ loader . loader === require . resolve ( "@svgr/webpack" )
49
+ ) {
50
+ if ( typeof loader . options === "object" ) {
51
+ loader . options . svgoConfig = NEW_SVGO_CONFIG ;
52
+ }
53
+ }
54
+ }
55
+ }
56
+ }
57
+ }
58
+ }
59
+ }
60
+ }
61
+ }
62
+
12
63
/** @type {import('@docusaurus/types').Config } */
13
64
const config = {
14
65
title : "MCAP" ,
@@ -34,6 +85,10 @@ const config = {
34
85
( _context , _options ) => ( {
35
86
name : "MCAP website custom webpack config" ,
36
87
configureWebpack ( config , _isServer , _utils , _content ) {
88
+ // Update config.module.rules directly.
89
+ // (Unclear if this is possible with a mergeStrategy below.)
90
+ modifySvgoConfig ( config ) ;
91
+
37
92
return {
38
93
mergeStrategy : {
39
94
"resolve.extensions" : "replace" ,
0 commit comments