Skip to content

Commit 496d33c

Browse files
committed
modify webpack config to address SVG issue
1 parent 0ff2bae commit 496d33c

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

website/docusaurus.config.js

+55
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,57 @@ const util = require("util");
99
const webpack = require("webpack");
1010
const execAsync = util.promisify(require("child_process").exec);
1111

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+
1263
/** @type {import('@docusaurus/types').Config} */
1364
const config = {
1465
title: "MCAP",
@@ -34,6 +85,10 @@ const config = {
3485
(_context, _options) => ({
3586
name: "MCAP website custom webpack config",
3687
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+
3792
return {
3893
mergeStrategy: {
3994
"resolve.extensions": "replace",

0 commit comments

Comments
 (0)