Skip to content

Commit 239ad51

Browse files
SoonIterTimeless0911
authored andcommitted
chore: update
1 parent d8f7eab commit 239ad51

File tree

1 file changed

+29
-27
lines changed

1 file changed

+29
-27
lines changed
Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
# 引用 SVGR
1+
# Referencing SVGR
22

3-
默认情况下,Rslib 会将 SVG 图片当作静态资源处理。
3+
By default, Rslib treats SVG images as static assets.
44

5-
通过添加 [@rsbuild/plugin-svgr](https://rsbuild.dev/zh/plugins/list/plugin-svgr) 插件,Rslib 支持调用 [SVGR](https://react-svgr.com/),将 SVG 图片转换为一个 React 组件使用。
5+
By adding the [@rsbuild/plugin-svgr](https://rsbuild.dev/en/plugins/list/plugin-svgr) plugin, Rslib supports invoking [SVGR](https://react-svgr.com/) to convert SVG images into React components for use.
66

7-
## 快速开始
7+
## Quick Start
88

9-
### 安装插件
9+
### Install the Plugin
1010

11-
你可以通过如下的命令安装插件:
11+
You can install the plugin using the following command:
1212

1313
import { PackageManagerTabs } from '@theme';
1414

1515
<PackageManagerTabs command="add @rsbuild/plugin-svgr -D" />
1616

17-
### 注册插件
17+
### Register the Plugin
1818

19-
你可以在 `rslib.config.ts` 文件中注册插件:
19+
You can register the plugin in the `rslib.config.ts` file:
2020

2121
```ts title="rslib.config.ts"
2222
import { pluginSvgr } from '@rsbuild/plugin-svgr';
@@ -26,40 +26,42 @@ export default {
2626
};
2727
```
2828

29-
## 示例
29+
## Examples
3030

31-
### Bundle 模式
31+
### Bundle Mode
3232

33-
Bundle 模式下,支持 [Rsbuild SVGR 插件](https://rsbuild.dev/zh/plugins/list/plugin-svgr) 下的所有用法,唯一的区别是当以 URL 形式使用 SVG 文件时,Rslib 会按照 [引用静态资源](/zh/guide/advanced/static-assets) 在产物中对应保留静态资源的 `import` 语句。
33+
In Bundle mode, all usages supported by the [Rsbuild SVGR plugin](https://rsbuild.dev/en/plugins/list/plugin-svgr) are available. The only difference is that when using an SVG file in URL form, Rslib will retain the `import` statement for the static asset in the output according to [Referencing Static Assets](/en/guide/advanced/static-assets).
3434

35-
下面是一个使用示例:
35+
Here is an example of usage:
3636

3737
```jsx title="App.jsx"
3838
import Logo from './logo.svg?react';
3939

4040
export const App = () => <Logo />;
4141
```
4242

43-
如果导入的路径不包含 `?react` 后缀,那么 SVG 会被当做普通的静态资源来处理,保留对静态资源的 `import` 语句。
43+
If the import path does not include the `?react` suffix, the SVG will be treated as a normal static asset, and the `import` statement for the static asset will be retained.
44+
45+
`@rsbuild/plugin-svgr` also supports default imports and mixed imports:
4446

4547
```js
4648
import logoURL from './static/logo.svg';
4749

4850
console.log(logoURL);
4951
```
5052

51-
`@rsbuild/plugin-svgr` 也支持默认导入和混合导入等用法:
53+
`@rsbuild/plugin-svgr` also supports default imports and mixed imports:
5254

53-
- 通过 [svgrOptions.exportType](https://rsbuild.dev/zh/plugins/list/plugin-svgr#svgroptionsexporttype) 设置为 `'default'` 来启用默认导入。
54-
- 通过 [mixedImport](https://rsbuild.dev/zh/plugins/list/plugin-svgr#mixedimport) 选项来启用混合导入,从而同时使用默认导入和具名导入。
55+
- Enable default imports by setting [svgrOptions.exportType](https://rsbuild.dev/en/plugins/list/plugin-svgr#svgroptionsexporttype) to `'default'`.
56+
- Enable mixed imports through the [mixedImport](https://rsbuild.dev/en/plugins/list/plugin-svgr#mixedimport) option to use both default and named imports.
5557

56-
### Bundleless 模式
58+
### Bundleless Mode
5759

58-
Bundleless 模式下,由于每个文件都是独立经过代码转换,因此不支持 `?react` `?url` 的引用形式,但支持下面两种使用形式:
60+
In Bundleless mode, since each file undergoes code transformation independently, the import ways of `?react` and `?url` are not supported. However, the following two usage forms are supported:
5961

60-
#### 具名导入
62+
#### Named Import
6163

62-
`@rsbuild/plugin-svgr` 支持具名导入 `ReactComponent` 来使用 SVGR,你需要设置 [svgrOptions.exportType](https://rsbuild.dev/zh/plugins/list/plugin-svgr#svgroptionsexporttype) `'named'`
64+
`@rsbuild/plugin-svgr` supports named import of `ReactComponent` to use SVGR. You need to set [svgrOptions.exportType](https://rsbuild.dev/en/plugins/list/plugin-svgr#svgroptionsexporttype) to `'named'`.
6365

6466
```js
6567
pluginSvgr({
@@ -75,14 +77,14 @@ import { ReactComponent as Logo } from './logo.svg';
7577
export const App = () => <Logo />;
7678
```
7779

78-
所有的 `.svg` 文件都会被转换成 React 组件,此时你可以:
80+
All `.svg` files will be converted into React components. At this time, you can:
7981

80-
- 通过设置 [exclude](https://rsbuild.dev/zh/plugins/list/plugin-svgr#exclude) 来排除不需要转换的文件。
81-
- 通过 [svgrOptions.exportType](https://rsbuild.dev/zh/plugins/list/plugin-svgr#svgroptionsexporttype) 设置为 `'default'` 来修改为默认导出。
82+
- Exclude files that do not need to be converted by setting [exclude](https://rsbuild.dev/en/plugins/list/plugin-svgr#exclude).
83+
- Change to default export by setting [svgrOptions.exportType](https://rsbuild.dev/en/plugins/list/plugin-svgr#svgroptionsexporttype) to `'default'`.
8284

83-
#### 混合导入
85+
#### Mixed Import
8486

85-
如果你的库中同时存在 url 和 React 组件两种引入形式,你也可以通过混合导入的方式来使用:
87+
If your library has both URL and React component import forms for SVG files, you can also use mixed imports.
8688

8789
```ts
8890
pluginSvgr({
@@ -93,7 +95,7 @@ pluginSvgr({
9395
});
9496
```
9597

96-
此时引用的 SVG 文件会同时导出 URL React 组件:
98+
At this time, the imported SVG file will export both the URL and the React component.
9799

98100
```js
99101
import logoUrl, { ReactComponent as Logo } from './logo.svg';
@@ -102,4 +104,4 @@ console.log(logoUrl); // -> string
102104
console.log(Logo); // -> React component
103105
```
104106

105-
更多信息可以参考 [mixedImport](https://rsbuild.dev/zh/plugins/list/plugin-svgr#mixedimport) 选项。
107+
For more information, refer to the [mixedImport](https://rsbuild.dev/en/plugins/list/plugin-svgr#mixedimport) option.

0 commit comments

Comments
 (0)