From 18a4e266478f35e10893045d393825ca5ce11a12 Mon Sep 17 00:00:00 2001 From: Rongjian Zhang Date: Wed, 20 Sep 2023 13:27:42 +0800 Subject: [PATCH] feat!: export as default with query --- client.d.ts | 6 ++++-- src/index.ts | 17 ++++------------- 2 files changed, 8 insertions(+), 15 deletions(-) diff --git a/client.d.ts b/client.d.ts index 0873443..dbfc650 100644 --- a/client.d.ts +++ b/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; } diff --git a/src/index.ts b/src/index.ts index 62e0e23..2d6b7ac 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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[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; @@ -41,7 +33,6 @@ export default function viteSvgr({ const componentCode = await transform(svgCode, svgrOptions, { filePath, caller: { - previousExport: exportAsDefault ? null : code, defaultPlugins: [jsx], }, });