Skip to content

Commit 8af77c7

Browse files
authored
Improve SVG handling (#1990)
* delete *.mini.svg and dupes, move nebula button in src * replace gatsby-plugin-react-svg with @svgr/webpack * update all svg import paths * huge homepage train SVG optimization * remove gatsby-plugin-react-svg dep
1 parent 584a414 commit 8af77c7

128 files changed

Lines changed: 9211 additions & 29848 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎gatsby-config.mjs‎

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -145,14 +145,6 @@ export default {
145145
path: './content/pages/404'
146146
}
147147
},
148-
{
149-
resolve: 'gatsby-plugin-react-svg',
150-
options: {
151-
rules: {
152-
include: './src/images'
153-
}
154-
}
155-
},
156148
'gatsby-plugin-netlify'
157149
]
158150
};

‎gatsby-node.mjs‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ import { createSchemaCustomization } from './gatsby/createSchemaCustomization.mj
22
import { createPages } from './gatsby/createPages.mjs';
33
import { createResolvers } from './gatsby/createResolvers.mjs';
44
import { onCreateNode } from './gatsby/onCreateNode.mjs';
5+
import { onCreateWebpackConfig } from './gatsby/onCreateWebpackConfig.mjs';
56

67
export {
78
createSchemaCustomization,
89
createPages,
910
createResolvers,
10-
onCreateNode
11+
onCreateNode,
12+
onCreateWebpackConfig
1113
};

‎gatsby/onCreateWebpackConfig.mjs‎

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import { createRequire } from 'node:module';
2+
3+
const require = createRequire(import.meta.url);
4+
5+
export const onCreateWebpackConfig = ({ actions, getConfig }) => {
6+
const config = getConfig();
7+
8+
// Exclude SVGs from the default file loader
9+
config.module.rules = config.module.rules.map((rule) => {
10+
if (rule.test?.toString().includes('svg')) {
11+
return { ...rule, exclude: /\.svg$/i };
12+
}
13+
return rule;
14+
});
15+
16+
// Handle SVGs as either emitted asset URLs (`?url`) or React components
17+
config.module.rules.push({
18+
test: /\.svg$/i,
19+
oneOf: [
20+
{
21+
resourceQuery: /url/,
22+
type: 'asset/resource'
23+
},
24+
{
25+
issuer: /\.[jt]sx?$/,
26+
use: [
27+
{
28+
loader: require.resolve('@svgr/webpack'),
29+
options: {
30+
svgo: true,
31+
svgoConfig: {
32+
multipass: true,
33+
plugins: [
34+
{
35+
name: 'preset-default',
36+
params: {
37+
overrides: {
38+
removeViewBox: false,
39+
inlineStyles: {
40+
onlyMatchedOnce: false
41+
}
42+
}
43+
}
44+
}
45+
]
46+
}
47+
}
48+
}
49+
]
50+
}
51+
]
52+
});
53+
54+
actions.replaceWebpackConfig(config);
55+
};

‎node-scripts/minify-svgs.mjs‎

Lines changed: 0 additions & 64 deletions
This file was deleted.

0 commit comments

Comments
 (0)