Skip to content

Commit

Permalink
feat!: export as default with query
Browse files Browse the repository at this point in the history
  • Loading branch information
pd4d10 committed Sep 20, 2023
1 parent c0e5b40 commit 18a4e26
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 15 deletions.
6 changes: 4 additions & 2 deletions client.d.ts
@@ -1,10 +1,12 @@
// https://github.com/facebook/create-react-app/blob/0ee4765c39f820e5f4820abf4bf2e47b3324da7f/packages/react-scripts/lib/react-app.d.ts#L47-L56
// https://github.com/pd4d10/vite-plugin-svgr/pull/56 for preact compatiblility

declare module "*.svg" {
declare module "*.svg?react" {
import * as React from "react";

export const ReactComponent: React.FunctionComponent<
const ReactComponent: React.FunctionComponent<
React.ComponentProps<"svg"> & { title?: string }
>;

export default ReactComponent;
}
17 changes: 4 additions & 13 deletions src/index.ts
Expand Up @@ -4,27 +4,19 @@ import fs from "fs";
import type { Plugin } from "vite";
import { transformWithEsbuild } from "vite";

export interface ViteSvgrOptions {
/**
* Export React component as default. Notice that it will overrides
* the default behavior of Vite, which exports the URL as default
*
* @default false
*/
exportAsDefault?: boolean;
export interface VitePluginSvgrOptions {
svgrOptions?: Config;
esbuildOptions?: Parameters<typeof transformWithEsbuild>[2];
exclude?: FilterPattern;
include?: FilterPattern;
}

export default function viteSvgr({
exportAsDefault,
export default function vitePluginSvgr({
svgrOptions,
esbuildOptions,
include = "**/*.svg",
include = "**/*.svg?react",
exclude,
}: ViteSvgrOptions = {}): Plugin {
}: VitePluginSvgrOptions = {}): Plugin {
const filter = createFilter(include, exclude);
const postfixRE = /[?#].*$/s;

Expand All @@ -41,7 +33,6 @@ export default function viteSvgr({
const componentCode = await transform(svgCode, svgrOptions, {
filePath,
caller: {
previousExport: exportAsDefault ? null : code,
defaultPlugins: [jsx],
},
});
Expand Down

0 comments on commit 18a4e26

Please sign in to comment.