Skip to content

Commit 18a4e26

Browse files
committed
feat!: export as default with query
1 parent c0e5b40 commit 18a4e26

File tree

2 files changed

+8
-15
lines changed

2 files changed

+8
-15
lines changed

client.d.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
// https://github.com/facebook/create-react-app/blob/0ee4765c39f820e5f4820abf4bf2e47b3324da7f/packages/react-scripts/lib/react-app.d.ts#L47-L56
22
// https://github.com/pd4d10/vite-plugin-svgr/pull/56 for preact compatiblility
33

4-
declare module "*.svg" {
4+
declare module "*.svg?react" {
55
import * as React from "react";
66

7-
export const ReactComponent: React.FunctionComponent<
7+
const ReactComponent: React.FunctionComponent<
88
React.ComponentProps<"svg"> & { title?: string }
99
>;
10+
11+
export default ReactComponent;
1012
}

src/index.ts

+4-13
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,19 @@ import fs from "fs";
44
import type { Plugin } from "vite";
55
import { transformWithEsbuild } from "vite";
66

7-
export interface ViteSvgrOptions {
8-
/**
9-
* Export React component as default. Notice that it will overrides
10-
* the default behavior of Vite, which exports the URL as default
11-
*
12-
* @default false
13-
*/
14-
exportAsDefault?: boolean;
7+
export interface VitePluginSvgrOptions {
158
svgrOptions?: Config;
169
esbuildOptions?: Parameters<typeof transformWithEsbuild>[2];
1710
exclude?: FilterPattern;
1811
include?: FilterPattern;
1912
}
2013

21-
export default function viteSvgr({
22-
exportAsDefault,
14+
export default function vitePluginSvgr({
2315
svgrOptions,
2416
esbuildOptions,
25-
include = "**/*.svg",
17+
include = "**/*.svg?react",
2618
exclude,
27-
}: ViteSvgrOptions = {}): Plugin {
19+
}: VitePluginSvgrOptions = {}): Plugin {
2820
const filter = createFilter(include, exclude);
2921
const postfixRE = /[?#].*$/s;
3022

@@ -41,7 +33,6 @@ export default function viteSvgr({
4133
const componentCode = await transform(svgCode, svgrOptions, {
4234
filePath,
4335
caller: {
44-
previousExport: exportAsDefault ? null : code,
4536
defaultPlugins: [jsx],
4637
},
4738
});

0 commit comments

Comments
 (0)