Skip to content

Commit 15225f5

Browse files
committed
feat: implement inline svg
1 parent b10cf82 commit 15225f5

File tree

3 files changed

+3188
-191
lines changed

3 files changed

+3188
-191
lines changed

Diff for: next.config.mjs

+54-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,59 @@
11
/** @type {import('next').NextConfig} */
22
const nextConfig = {
3-
// basePath: '/inbox/playground',
4-
// assetPrefix: '/inbox/playground/',
3+
webpack(config) {
4+
const fileLoaderRule = config.module.rules.find((rule) => rule.test?.test?.(".svg"));
5+
6+
config.module.rules.push(
7+
// Reapply the existing rule, but only for svg imports not ending in ".inline.svg"
8+
{
9+
test: /(?<!inline)\.svg$/,
10+
use: [
11+
{
12+
loader: "url-loader",
13+
options: {
14+
limit: 512,
15+
publicPath: "/_next/static/svgs",
16+
outputPath: "static/svgs",
17+
fallback: "file-loader",
18+
},
19+
},
20+
{
21+
loader: "svgo-loader",
22+
},
23+
],
24+
},
25+
// Convert all other *.svg imports to React components
26+
{
27+
test: /\.inline.svg$/i,
28+
use: [
29+
{
30+
loader: "@svgr/webpack",
31+
options: {
32+
svgo: true,
33+
svgoConfig: {
34+
plugins: [
35+
{
36+
name: "preset-default",
37+
params: {
38+
overrides: {
39+
removeViewBox: false,
40+
},
41+
},
42+
},
43+
"prefixIds",
44+
],
45+
},
46+
},
47+
},
48+
],
49+
},
50+
);
51+
52+
// Modify the file loader rule to ignore *.svg, since we have it handled now.
53+
fileLoaderRule.exclude = /\.svg$/i;
54+
55+
return config;
56+
},
557
};
658

759
export default nextConfig;

0 commit comments

Comments
 (0)