-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
import SVG directly as a React Component #2269
Comments
This is React specific and can be only be done via plugins. |
@svgr/rollup resolved that |
{
...svgr({
memo: true,
icon: true,
svgoConfig: {
removeViewBox: false
}
}),
enforce: 'pre',
}
import { ReactComponent as Logo } from './logo.svg'; Update:
I figured out the issue. It's specific to Typescript. The declaration of module Also, since Also, there is no way (that I am aware of) to override already existing declare statements in
Is it ok to add support for typescript declarations for |
@phoenisx Just add this to declare module "*.svg" {
import * as React from "react";
export const ReactComponent: React.FunctionComponent<
React.SVGProps<SVGSVGElement> & { title?: string }
>;
} |
Is there any way to disable the use of the existing SVG transformer? Sure, this works as a workaround, but it leaves a lot to be desired. First, the SVG assets are still copied to the output. Second, the default export cannot be overwritten, leaving needless use of named imports instead. The typing can be solved by not specifying |
@AlexGustafsson Please open a new issue for that 👍 |
This issue has been locked since it has been closed for more than 14 days. If you have found a concrete bug or regression related to it, please open a new bug report with a reproduction against the latest Vite version. If you have any other comments you should join the chat at Vite Land or create a new discussion. |
希望能像cra一样 既提供导出svg资源,又支持导出组件
import { ReactComponent as Logo } from "logo.svg"
import logo from "logo.svg"
The text was updated successfully, but these errors were encountered: