Skip to content

Commit 2a74a2f

Browse files
authored
docs: translate Rsbuild configurations (#543)
1 parent 4073e70 commit 2a74a2f

File tree

10 files changed

+255
-13
lines changed

10 files changed

+255
-13
lines changed

website/docs/en/config/rsbuild/index.mdx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ To learn more about Rslib configurations, check out [Configure Rslib](/guide/bas
1111

1212
## Overview
1313

14-
- [source](/config/rsbuild/source): Configure the source code parsing and compilation options.
15-
- [output](/config/rsbuild/output): Configure the build outputs.
16-
- [tools](/config/rsbuild/tools): Configure the low-level tools.
14+
- [resolve](/config/rsbuild/resolve): Options for module resolution.
15+
- [source](/config/rsbuild/source): Options for input source code.
16+
- [output](/config/rsbuild/output): Options for build outputs.
17+
- [tools](/config/rsbuild/tools): Options for low-level tools.
1718
- [plugins](/config/rsbuild/plugins): Configure Rsbuild plugins.

website/docs/en/config/rsbuild/output.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { RsbuildDocBadge } from '@components/RsbuildDocBadge';
22

33
# output
44

5-
Configure the build outputs.
5+
Options for build outputs.
66

77
{/* ## output.assetPrefix <RsbuildDocBadge path="/config/output/asset-prefix" text="output.assetPrefix" /> */}
88

website/docs/en/config/rsbuild/resolve.mdx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@ import { RsbuildDocBadge } from '@components/RsbuildDocBadge';
22

33
# resolve
44

5+
Options for module resolution.
6+
57
## resolve.aliasStrategy <RsbuildDocBadge path="/config/resolve/alias-strategy" text="resolve.aliasStrategy" />
68

7-
`resolve.aliasStrategy` is used to control the priority between the `paths` option in `tsconfig.json` and the `alias` option in the bundler.
9+
Control the priority between the `paths` option in `tsconfig.json` and the `resolve.alias` option of Rsbuild.
810

911
## resolve.alias <RsbuildDocBadge path="/config/resolve/alias" text="resolve.alias" />
1012

@@ -14,7 +16,7 @@ It is important to note that `resolve.alias` differs from [output.externals](/co
1416

1517
- `resolve.alias` allows you to replace the target module you want to include in the output bundles with another module. It only works if [lib.bundle](/config/lib/bundle) is set to `true`.
1618

17-
For example, if you want to replace `lodash` with `lodash-es` in a bundled CLI application, you can configure it as follows:
19+
For example, if you want to replace `lodash` with `lodash-es` when bundling a package, you can configure it as follows:
1820

1921
```ts title="rslib.config.ts"
2022
export default {
@@ -49,4 +51,8 @@ It is important to note that `resolve.alias` differs from [output.externals](/co
4951

5052
## resolve.dedupe <RsbuildDocBadge path="/config/resolve/dedupe" text="resolve.dedupe" />
5153

52-
`resolve.dedupe` is used to resolve the specified packages from project root, which is useful for deduplicating packages and reducing the bundle size.
54+
Force Rsbuild to resolve the specified packages from project root, which is useful for deduplicating packages and reducing the bundle size.
55+
56+
## resolve.extensions <RsbuildDocBadge path="/config/resolve/extensions" text="resolve.extensions" />
57+
58+
Automatically resolve file extensions when importing modules. This means you can import files without explicitly writing their extensions.

website/docs/en/config/rsbuild/source.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { RsbuildDocBadge } from '@components/RsbuildDocBadge';
33

44
# source
55

6-
Configure the source code parsing and compilation options.
6+
Options for input source code.
77

88
## source.assetsInclude <RsbuildDocBadge path="/config/source/assets-include" text="source.include" />
99

@@ -27,11 +27,11 @@ Check out the [lib.bundle](/config/lib/bundle#set-entry) to learn how to set ent
2727

2828
## source.exclude <RsbuildDocBadge path="/config/source/exclude" text="source.exclude" />
2929

30-
Specifies JavaScript/TypeScript files that do not need to be compiled. The usage is consistent with [Rule.exclude](https://rspack.dev/config/module#ruleexclude) in Rspack, which supports passing in strings or regular expressions to match the module path.
30+
Specifies JavaScript/TypeScript files that do not need to be compiled.
3131

3232
## source.include <RsbuildDocBadge path="/config/source/include" text="source.include" />
3333

34-
The `source.include` is used to specify additional JavaScript files that need to be compiled.
34+
Specify additional JavaScript files that need to be compiled.
3535

3636
{/* ## source.preEntry <RsbuildDocBadge path="/config/source/pre-entry" text="source.preEntry" /> */}
3737

website/docs/en/config/rsbuild/tools.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ import { RsbuildDocBadge } from '@components/RsbuildDocBadge';
22

33
# tools
44

5-
Configure the low-level tools.
5+
Options for low-level tools.
66

77
## tools.bundlerChain <RsbuildDocBadge path="/config/tools/bundler-chain" text="tools.bundlerChain" />
88

9-
[rspack-chain](https://github.com/rspack-contrib/rspack-chain) is a utility library for configuring Rspack.
9+
[rspack-chain](https://github.com/rspack-contrib/rspack-chain) is a utility library for configuring Rspack. By using `rspack-chain`, you can more easily modify and extend Rspack configurations.
1010

1111
{/* ## tools.cssExtract <RsbuildDocBadge path="/config/tools/css-extract" text="tools.cssExtract" /> */}
1212

@@ -30,7 +30,7 @@ Rsbuild integrates PostCSS by default, you can configure [postcss-loader](https:
3030

3131
## tools.rspack <RsbuildDocBadge path="/config/tools/rspack" text="tools.rspack" />
3232

33-
`tools.rspack` is used to configure [Rspack](https://rspack.dev/).
33+
`tools.rspack` is used to configure [Rspack](https://rspack.dev/config/index).
3434

3535
## tools.styleLoader <RsbuildDocBadge path="/config/tools/style-loader" text="tools.styleLoader" />
3636

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,17 @@
1+
import { RsbuildDocBadge } from '@components/RsbuildDocBadge';
2+
13
# Rsbuild 配置
4+
5+
Rslib 继承了 Rsbuild 的配置,所以你也可以配置 <RsbuildDocBadge path="/config" text="config" /> 选项。本章节介绍了一些常见的配置项,并解释了如何在 Rslib 中使用它们。
6+
7+
:::tip
8+
要了解更多关于 Rslib 的配置,请查看 [Configure Rslib](/guide/basic/configure-rslib)
9+
:::
10+
11+
## 概览
12+
13+
- [resolve](/config/rsbuild/resolve): 与模块解析相关的选项。
14+
- [source](/config/rsbuild/source): 与输入的源代码相关的选项。
15+
- [output](/config/rsbuild/output): 与构建产物相关的选项。
16+
- [tools](/config/rsbuild/tools): 与底层工具相关的选项。
17+
- [plugins](/config/rsbuild/plugins): 配置 Rsbuild 插件。
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,91 @@
1+
import { RsbuildDocBadge } from '@components/RsbuildDocBadge';
2+
13
# output
4+
5+
与构建产物相关的选项。
6+
7+
## output.charset <RsbuildDocBadge path="/config/output/charset" text="output.charset" />
8+
9+
指定输出文件的 [字符编码](https://developer.mozilla.org/en-US/docs/Glossary/Character_encoding),以确保它们在不同的环境中能够正确显示。
10+
11+
## output.cleanDistPath <RsbuildDocBadge path="/config/output/clean-dist-path" text="output.cleanDistPath" />
12+
13+
是否在构建开始前清理产物目录下的所有文件(产物目录默认为 `dist`)。
14+
15+
## output.copy <RsbuildDocBadge path="/config/output/copy" text="output.copy" />
16+
17+
将指定的文件或目录拷贝到构建输出目录中,基于 [rspack.CopyRspackPlugin](https://rspack.dev/zh/plugins/rspack/copy-rspack-plugin) 实现。
18+
19+
## output.cssModules <RsbuildDocBadge path="/config/output/css-modules" text="output.cssModules" />
20+
21+
用于自定义 CSS Modules 配置。
22+
23+
## output.dataUriLimit <RsbuildDocBadge path="/config/output/data-uri-limit" text="output.dataUriLimit" />
24+
25+
设置图片、字体、媒体等静态资源被自动内联为 base64 的体积阈值。
26+
27+
## output.distPath <RsbuildDocBadge path="/config/output/dist-path" text="output.distPath" />
28+
29+
设置构建产物的输出目录,Rsbuild 会根据产物的类型输出到对应的子目录下。
30+
31+
## output.emitCss <RsbuildDocBadge path="/config/output/emit-css" text="output.emitCss" />
32+
33+
是否将 CSS 输出到产物中。
34+
35+
## output.externals <RsbuildDocBadge path="/config/output/externals" text="output.externals" />
36+
37+
在构建时,防止将代码中某些 `import` 的依赖包打包到 bundle 中,而是在运行时再去从外部获取这些依赖。
38+
39+
需要注意的是,`output.externals`[resolve.alias](/config/rsbuild/resolve#resolvealias) 有所不同。请查看 [resolve.alias](/config/rsbuild/resolve#resolvealias) 文档以了解更多信息。
40+
41+
## output.filenameHash <RsbuildDocBadge path="/config/output/filename-hash" text="output.filenameHash" />
42+
43+
在生产模式构建后,是否在产物的文件名中添加 hash 值。
44+
45+
## output.filename <RsbuildDocBadge path="/config/output/filename" text="output.filename" />
46+
47+
设置构建产物的名称。
48+
49+
## output.inlineScripts <RsbuildDocBadge path="/config/output/inline-scripts" text="output.inlineScripts" />
50+
51+
用来控制是否用 `<script>` 标签将产物中的 script 文件(.js 文件)inline 到 HTML 中。
52+
53+
## output.inlineStyles <RsbuildDocBadge path="/config/output/inline-styles" text="output.inlineStyles" />
54+
55+
用来控制是否用 `<style>` 标签将产物中的 style 文件(.css 文件)inline 到 HTML 中。
56+
57+
## output.legalComments <RsbuildDocBadge path="/config/output/legal-comments" text="output.legalComments" />
58+
59+
配置 legal comment 的处理方式。
60+
61+
## output.manifest <RsbuildDocBadge path="/config/output/manifest" text="output.manifest" />
62+
63+
是否生成 manifest 文件,该文件包含所有构建产物的信息、以及[入口模块](https://rsbuild.dev/zh/config/source/entry)与构建产物间的映射关系。
64+
65+
## output.minify <RsbuildDocBadge path="/config/output/minify" text="output.minify" />
66+
67+
用于设置是否在生产模式下开启代码压缩,或是配置压缩工具的选项。
68+
69+
## output.overrideBrowserslist <RsbuildDocBadge path="/config/output/override-browserslist" text="output.overrideBrowserslist" />
70+
71+
指定项目兼容的目标浏览器范围。
72+
73+
## output.polyfill <RsbuildDocBadge path="/config/output/polyfill" text="output.polyfill" />
74+
75+
控制 polyfills 的注入方式。
76+
77+
:::warning
78+
Rsbuild 的 `output.polyfill` 会将 polyfills 注入到全局作用域中,这可能会意外地修改库消费者的全局变量。对于非全局的 polyfill 方案,请参考 [Polyfill - 浏览器](/guide/advanced/output-compatibility#浏览器)
79+
:::
80+
81+
## output.sourceMap <RsbuildDocBadge path="/config/output/source-map" text="output.sourceMap" />
82+
83+
用于设置是否生成 source map 文件,以及生成哪一种格式的 source map。
84+
85+
## output.target <RsbuildDocBadge path="/config/output/target" text="output.target" />
86+
87+
用于设置 Rsbuild 的构建产物类型。
88+
89+
:::info
90+
请查看 [解决方案](/guide/solution/) 了解更多关于构建产物的信息。
91+
:::
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,58 @@
1+
import { RsbuildDocBadge } from '@components/RsbuildDocBadge';
2+
13
# resolve
4+
5+
与模块解析相关的选项。
6+
7+
## resolve.aliasStrategy <RsbuildDocBadge path="/config/resolve/alias-strategy" text="resolve.aliasStrategy" />
8+
9+
控制 `tsconfig.json` 中的 `paths` 选项与 Rsbuild 中的 `resolve.alias` 选项的优先级。
10+
11+
## resolve.alias <RsbuildDocBadge path="/config/resolve/alias" text="resolve.alias" />
12+
13+
设置文件引用的别名,对应 Rspack 的 [resolve.alias](https://rspack.dev/zh/config/resolve#resolvealias) 配置。
14+
15+
值得注意的是,`resolve.alias`[output.externals](/config/rsbuild/output#outputexternals) 在以下方面有所不同:
16+
17+
- `resolve.alias` 允许你将目标模块替换为另一个模块。它仅在 [lib.bundle](/config/lib/bundle) 设置为 `true` 时有效。
18+
19+
例如,如果你想在打包一个 package 时将 `lodash` 替换为 `lodash-es`,可以这样配置:
20+
21+
```ts title="rslib.config.ts"
22+
export default {
23+
// ...
24+
resolve: {
25+
alias: {
26+
lodash: 'lodash-es',
27+
},
28+
},
29+
};
30+
```
31+
32+
所有在源代码中导入的 `lodash` 模块将被映射为 `lodash-es`,并被打包到产物中。
33+
34+
- `output.externals` 用于处理外部化模块的别名映射。外部化模块不会被打包到产物中,而是在运行时从外部源导入。
35+
36+
例如,如果你想在 bundle 中将 `react``react-dom` 替换为 `preact/compat`,可以这样配置:
37+
38+
```ts title="rslib.config.ts"
39+
export default {
40+
// ...
41+
output: {
42+
externals: {
43+
react: 'preact/compat',
44+
'react-dom': 'preact/compat',
45+
},
46+
},
47+
};
48+
```
49+
50+
此时,代码 `import { useState } from 'react'` 将被替换为 `import { useState } from 'preact/compat'`
51+
52+
## resolve.dedupe <RsbuildDocBadge path="/config/resolve/dedupe" text="resolve.dedupe" />
53+
54+
强制 Rsbuild 从项目根目录解析指定的包,这可以用于移除重复包和减少包大小。
55+
56+
## resolve.extensions <RsbuildDocBadge path="/config/resolve/extensions" text="resolve.extensions" />
57+
58+
自动添加导入文件的扩展名。这意味着你可以导入文件,而不需要显式地写它们的扩展名。
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,41 @@
1+
import { RsbuildDocBadge } from '@components/RsbuildDocBadge';
2+
13
# source
4+
5+
与输入的源代码相关的选项。
6+
7+
## source.assetsInclude <RsbuildDocBadge path="/config/source/assets-include" text="source.include" />
8+
9+
指定需要被视为静态资源的额外文件类型。
10+
11+
## source.decorators <RsbuildDocBadge path="/config/source/decorators" text="source.decorators" />
12+
13+
用于配置装饰器语法。
14+
15+
## source.define <RsbuildDocBadge path="/config/source/define" text="source.define" />
16+
17+
构建时将代码中的变量替换成其它值或者表达式,可以用于在代码逻辑中区分开发模式与生产模式等场景。
18+
19+
## source.entry <RsbuildDocBadge path="/config/source/entry" text="source.entry" />
20+
21+
用于设置构建的入口模块。
22+
23+
:::info
24+
参考 [lib.bundle](/config/lib/bundle#set-entry) 了解如何为 bundle 和 bundleless 项目设置入口。
25+
:::
26+
27+
## source.exclude <RsbuildDocBadge path="/config/source/exclude" text="source.exclude" />
28+
29+
指定不需要编译的 JavaScript/TypeScript 文件。
30+
31+
## source.include <RsbuildDocBadge path="/config/source/include" text="source.include" />
32+
33+
指定额外需要编译的 JavaScript 文件。
34+
35+
## source.transformImport <RsbuildDocBadge path="/config/source/transform-import" text="source.transformImport" />
36+
37+
转换 import 的路径,可以用于模块化引用三方包的子路径,能力类似于 [babel-plugin-import](https://npmjs.com/package/babel-plugin-import)
38+
39+
## source.tsconfigPath <RsbuildDocBadge path="/config/source/tsconfig-path" text="source.tsconfigPath" />
40+
41+
配置自定义的 tsconfig.json 文件路径,可以是相对路径或绝对路径。
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,33 @@
1+
import { RsbuildDocBadge } from '@components/RsbuildDocBadge';
2+
13
# tools
4+
5+
与底层工具相关的选项。
6+
7+
## tools.bundlerChain <RsbuildDocBadge path="/config/tools/bundler-chain" text="tools.bundlerChain" />
8+
9+
[rspack-chain](https://github.com/rspack-contrib/rspack-chain) 是一个用于配置 Rspack 的工具库,通过 `tools.bundlerChain` 可以调用 `rspack-chain` 以修改默认的 Rspack 配置。
10+
11+
## tools.cssLoader <RsbuildDocBadge path="/config/tools/css-loader" text="tools.cssLoader" />
12+
13+
Rsbuild 默认使用 [css-loader](https://github.com/webpack-contrib/css-loader) 来处理 CSS 资源。你可以通过 `tools.cssLoader` 来修改 css-loader 的选项。
14+
15+
## tools.lightningcssLoader <RsbuildDocBadge path="/config/tools/lightningcss-loader" text="tools.lightningcssLoader" />
16+
17+
通过 `tools.lightningcssLoader` 可以设置 [builtin:lightningcss-loader](https://rspack.dev/zh/guide/features/builtin-lightningcss-loader) 的选项。
18+
19+
## tools.postcss <RsbuildDocBadge path="/config/tools/postcss" text="tools.postcss" />
20+
21+
Rsbuild 默认集成 PostCSS,你可以通过 `tools.postcss`[postcss-loader](https://github.com/webpack-contrib/postcss-loader) 进行配置。
22+
23+
## tools.rspack <RsbuildDocBadge path="/config/tools/rspack" text="tools.rspack" />
24+
25+
`tools.rspack` 选项用于修改 [Rspack](https://rspack.dev/zh/config/index) 的配置项。
26+
27+
## tools.styleLoader <RsbuildDocBadge path="/config/tools/style-loader" text="tools.styleLoader" />
28+
29+
通过 `tools.styleLoader` 可以设置 [style-loader](https://github.com/webpack-contrib/style-loader) 的配置项。
30+
31+
## tools.swc <RsbuildDocBadge path="/config/tools/swc" text="tools.swc" />
32+
33+
通过 `tools.swc` 可以设置 [builtin:swc-loader](https://rspack.dev/zh/guide/features/builtin-swc-loader) 的选项。

0 commit comments

Comments
 (0)