mirror of
https://github.com/ant-design/ant-design.git
synced 2024-11-27 12:39:49 +08:00
parent
c1566bead4
commit
fe0f6920a7
@ -155,10 +155,22 @@ module.exports = {
|
||||
};
|
||||
```
|
||||
|
||||
You can import SVG icon as a react component by using `vite` and [`vite-plugin-svgr`](https://www.npmjs.com/package/vite-plugin-svgr). `@svgr/webpack`'s `options` [reference](https://github.com/smooth-code/svgr#options).
|
||||
|
||||
```js
|
||||
// vite.config.js
|
||||
export default defineConfig(() => ({
|
||||
// ... other config
|
||||
plugins: [svgr({ svgrOptions: { icon: true } })],
|
||||
}));
|
||||
```
|
||||
|
||||
```jsx
|
||||
import React from 'react';
|
||||
import Icon from '@ant-design/icons';
|
||||
import MessageSvg from 'path/to/message.svg'; // path to your '*.svg' file.
|
||||
|
||||
// import MessageSvg from 'path/to/message.svg?react'; // use vite path to your '*.svg?react' file.
|
||||
import ReactDOM from 'react-dom/client';
|
||||
|
||||
// in create-react-app:
|
||||
|
@ -150,10 +150,22 @@ module.exports = {
|
||||
};
|
||||
```
|
||||
|
||||
如果使用 `vite`,可以通过配置 [vite-plugin-svgr](https://www.npmjs.com/package/vite-plugin-svgr) 来将 `svg` 图标作为 `React` 组件导入。`vite-plugin-svgr` 的 `options` 选项请参阅 [svgr 文档](https://github.com/smooth-code/svgr#options)。
|
||||
|
||||
```js
|
||||
// vite.config.js
|
||||
export default defineConfig(() => ({
|
||||
// ... other config
|
||||
plugins: [svgr({ svgrOptions: { icon: true } })],
|
||||
}));
|
||||
```
|
||||
|
||||
```jsx
|
||||
import React from 'react';
|
||||
import Icon from '@ant-design/icons';
|
||||
import MessageSvg from 'path/to/message.svg'; // 你的 '*.svg' 文件路径
|
||||
|
||||
// import MessageSvg from 'path/to/message.svg?react'; // 使用vite 你的 '*.svg?react' 文件路径.
|
||||
import ReactDOM from 'react-dom/client';
|
||||
|
||||
// in create-react-app:
|
||||
|
Loading…
Reference in New Issue
Block a user