Skip to content

Commit b2ea6b6

Browse files
committed
More svgr config
1 parent c1611e5 commit b2ea6b6

3 files changed

Lines changed: 41 additions & 5 deletions

File tree

dotcom-rendering/index.d.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,20 @@ declare module 'dynamic-import-polyfill' {
1515
}
1616

1717
// SVG handling
18+
// declare module '*.svg' {
19+
// const content: any;
20+
// // eslint-disable-next-line import/no-default-export -- This is how we import SVGs
21+
// export default content;
22+
// }
1823
declare module '*.svg' {
19-
const content: any;
20-
// eslint-disable-next-line import/no-default-export -- This is how we import SVGs
21-
export default content;
24+
import type React from 'react';
25+
26+
const ReactComponent: React.FunctionComponent<
27+
React.SVGProps<SVGSVGElement> & { title?: string }
28+
>;
29+
30+
// eslint-disable-next-line import/no-default-export -- vite poc
31+
export default ReactComponent;
2232
}
2333

2434
// Extend PerformanceEntry from lib.dom.ts with current 'In Draft' properties (to allow access as use in browsers that support)

dotcom-rendering/src/server/server.dev.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import react from '@vitejs/plugin-react-swc';
12
import express, { type Handler, Router } from 'express';
23
import { createServer } from 'vite';
34
import svgr from 'vite-plugin-svgr';
@@ -136,7 +137,23 @@ export const devServer = async (): Promise<void> => {
136137
const vite = await createServer({
137138
server: { middlewareMode: true },
138139
appType: 'custom',
139-
plugins: [svgr()],
140+
plugins: [
141+
react({
142+
jsxImportSource: '@emotion/react',
143+
parserConfig: { tsx: true },
144+
}),
145+
svgr({
146+
// svgr options: https://react-svgr.com/docs/options/
147+
svgrOptions: {
148+
exportType: 'default',
149+
ref: true,
150+
svgo: false,
151+
titleProp: true,
152+
},
153+
include: '**/*.svg',
154+
}),
155+
],
156+
// plugins: [svgr()],
140157
});
141158
console.log('!!! Vite httpServer:', vite.httpServer);
142159

dotcom-rendering/vite.config.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,16 @@ export default defineConfig({
4040
jsxImportSource: '@emotion/react',
4141
parserConfig: { tsx: true },
4242
}),
43-
svgr(),
43+
svgr({
44+
// svgr options: https://react-svgr.com/docs/options/
45+
svgrOptions: {
46+
exportType: 'default',
47+
ref: true,
48+
svgo: false,
49+
titleProp: true,
50+
},
51+
include: '**/*.svg',
52+
}),
4453
],
4554
resolve: {
4655
alias: {

0 commit comments

Comments
 (0)