Skip to content

Commit f4c41c0

Browse files
docs(zh): translate /config/lib to Chinese (#526)
Co-authored-by: Timeless0911 <[email protected]>
1 parent 9f183ae commit f4c41c0

23 files changed

+1171
-31
lines changed

packages/core/src/types/config/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,13 +132,13 @@ export interface LibConfig extends RsbuildConfig {
132132
*/
133133
externalHelpers?: boolean;
134134
/**
135-
* Inject content into the top of each JS, CSS or DTS file.
135+
* Inject content into the top of each JavaScript, CSS or DTS file.
136136
* @defaultValue `{}`
137137
* @see {@link https://lib.rsbuild.dev/config/lib/banner}
138138
*/
139139
banner?: BannerAndFooter;
140140
/**
141-
* Inject content into the bottom of each JS, CSS or DTS file.
141+
* Inject content into the bottom of each JavaScript, CSS or DTS file.
142142
* @defaultValue `{}`
143143
* @see {@link https://lib.rsbuild.dev/config/lib/footer}
144144
*/

website/docs/en/config/lib/auto-extension.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ By default that when `autoExtension` is set to `true`, the file extension will b
1515

1616
:::warning
1717

18-
When [bundle](/config/lib/bundle) is set to `false` that as known as bundleless mode, you should write full path instead of ignoring directory indexes (e.g. `'./foo/index.js'`) in source code.
18+
When [bundle](/config/lib/bundle) is set to `false` that as known as bundleless mode, you should write full path instead of ignoring directory indexes (e.g. using `'./foo'` as a shorthand for `'./foo/index.js'`) in source code.
1919

2020
For example, if `foo` is a folder, you need to rewrite `import * from './foo'` to `import * from './foo/index'`.
2121

website/docs/en/config/lib/auto-external.mdx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,28 +28,28 @@ Whether to automatically externalize dependencies of different dependency types
2828
- **Type:** `boolean`
2929
- **Default:** `true`
3030

31-
Whether to externalize dependencies of type `dependencies`.
31+
Whether to automatically externalize dependencies of type `dependencies`.
3232

3333
### autoExternal.optionalDependencies
3434

3535
- **Type:** `boolean`
3636
- **Default:** `true`
3737

38-
Whether to externalize dependencies of type `optionalDependencies`.
38+
Whether to automatically externalize dependencies of type `optionalDependencies`.
3939

4040
### autoExternal.peerDependencies
4141

4242
- **Type:** `boolean`
4343
- **Default:** `true`
4444

45-
Whether to externalize dependencies of type `peerDependencies`.
45+
Whether to automatically externalize dependencies of type `peerDependencies`.
4646

4747
### autoExternal.devDependencies
4848

4949
- **Type:** `boolean`
5050
- **Default:** `false`
5151

52-
Whether to bundle dependencies of type `devDependencies`.
52+
Whether to automatically externalize dependencies of type `devDependencies`.
5353

5454
## Default Value
5555

website/docs/en/config/lib/banner.mdx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ type Banner = {
1616

1717
- **Default:** `{}`
1818

19-
Inject content into the top of each JS, CSS or DTS file.
19+
Inject content into the top of each JavaScript, CSS or DTS output file.
2020

2121
## Object Type
2222

@@ -25,25 +25,25 @@ Inject content into the top of each JS, CSS or DTS file.
2525
- **Type:** `string`
2626
- **Default:** `undefined`
2727

28-
Inject content into the top of each JS file.
28+
Inject content into the top of each JavaScript output file.
2929

3030
### banner.css
3131

3232
- **Type:** `string`
3333
- **Default:** `undefined`
3434

35-
Inject content into the top of each CSS file.
35+
Inject content into the top of each CSS output file.
3636

3737
### banner.dts
3838

3939
- **Type:** `string`
4040
- **Default:** `undefined`
4141

42-
Inject content into the top of each DTS file.
42+
Inject content into the top of each DTS output file.
4343

4444
## Notice
4545

46-
The banner content in JS/CSS file is based on the [BannerPlugin](https://rspack.dev/plugins/webpack/banner-plugin) of Rspack. You should notice the following points:
46+
The banner content in JavaScript and CSS file is based on the [BannerPlugin](https://rspack.dev/plugins/webpack/banner-plugin) of Rspack. You should notice the following points:
4747

4848
- `raw: true` is enabled by default, so the banner content will be injected as a raw string instead of wrapping in a comment. So if you want to inject a comment, you should add `/*` and `*/` or other comment syntax by yourself.
4949
- The `stage` option is set to the stage after the JavaScript and CSS files are optimized, thus preventing the banner content from being optimized away.
@@ -73,6 +73,6 @@ export default {
7373

7474
:::warning
7575

76-
The banner content in DTS files is handled differently from JS/CSS files. It is written directly using the file system API, so setting `BannerPlugin` will not affect it.
76+
The banner content in DTS files is handled differently from JavaScript and CSS output files. It is written directly using the file system API, so setting `BannerPlugin` will not affect it.
7777

7878
:::

website/docs/en/config/lib/dts.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ Whether to bundle the DTS files.
6565

6666
If you want to [bundle DTS](/guide/advanced/dts#bundle-dts) files, you should:
6767

68-
1. Install `@microsoft/api-extractor` as a development dependency, which is the underlying tool used for bundling DTS files.
68+
1. Install [@microsoft/api-extractor](https://www.npmjs.com/package/@microsoft/api-extractor) as a development dependency, which is the underlying tool used for bundling DTS files.
6969

7070
import { PackageManagerTabs } from '@theme';
7171

@@ -88,7 +88,7 @@ export default {
8888

8989
::: note
9090

91-
[@microsoft/api-extractor](https://github.com/microsoft/rushstack/tree/main/apps/api-extractor) only supports bundle DTS for single entry. If you want to generate bundle DTS for multiple entries, you can add extra lib configuration in [lib](/config/lib/) field to split multiple entries into multiple lib configurations.
91+
[@microsoft/api-extractor](https://www.npmjs.com/package/@microsoft/api-extractor) only supports bundle DTS for single entry. If you want to generate bundle DTS for multiple entries, you can add extra lib configuration in [lib](/config/lib/) field to split multiple entries into multiple lib configurations.
9292

9393
:::
9494

website/docs/en/config/lib/external-helpers.mdx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ When `externalHelpers` set to `true`, the output JavaScript will import helper f
1111

1212
::: note
1313

14-
Make sure to declare the `@swc/helpers` in `dependencies` field of `package.json`.
14+
Make sure to declare and install `@swc/helpers` in `dependencies` field of `package.json`.
1515

1616
:::
1717

@@ -39,9 +39,9 @@ export default {
3939
};
4040
```
4141

42-
Below is the output JavaScript file:
42+
Below is the output JavaScript file, the highlighted code is the inlined helper functions:
4343

44-
```js title="index.js"
44+
```js title="index.js" {1-18}
4545
function _class_call_check(instance, Constructor) {
4646
if (!(instance instanceof Constructor))
4747
throw new TypeError('Cannot call a class as a function');
@@ -88,7 +88,7 @@ export default {
8888
};
8989
```
9090

91-
Below is the output JavaScript file:
91+
Below is the output JavaScript file, the highlighted code is importing helper functions:
9292

9393
```js title="index.js" {1-2}
9494
import * as __WEBPACK_EXTERNAL_MODULE__swc_helpers_class_call_check__ from '@swc/helpers/_/_class_call_check';

website/docs/en/config/lib/footer.mdx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ type Footer = {
1616

1717
- **Default:** `{}`
1818

19-
Inject content into the bottom of each JS, CSS or DTS file.
19+
Inject content into the bottom of each JavaScript, CSS or DTS file.
2020

2121
## Object Type
2222

@@ -25,25 +25,25 @@ Inject content into the bottom of each JS, CSS or DTS file.
2525
- **Type:** `string`
2626
- **Default:** `undefined`
2727

28-
Inject content into the bottom of each JS file.
28+
Inject content into the bottom of each JavaScript output file.
2929

3030
### footer.css
3131

3232
- **Type:** `string`
3333
- **Default:** `undefined`
3434

35-
Inject content into the bottom of each CSS file.
35+
Inject content into the bottom of each CSS output file.
3636

3737
### footer.dts
3838

3939
- **Type:** `string`
4040
- **Default:** `undefined`
4141

42-
Inject content into the bottom of each DTS file.
42+
Inject content into the bottom of each DTS output file.
4343

4444
## Notice
4545

46-
The footer content in JS/CSS file is based on the [BannerPlugin](https://rspack.dev/plugins/webpack/banner-plugin) of Rspack. You should notice the following points:
46+
The footer content in JavaScript and CSS file is based on the [BannerPlugin](https://rspack.dev/plugins/webpack/banner-plugin) of Rspack. You should notice the following points:
4747

4848
- `raw: true` is enabled by default, so the footer content will be injected as a raw string instead of wrapping in a comment. So if you want to inject a comment, you should add `/*` and `*/` or other comment syntax by yourself.
4949
- The `stage` option is set to the stage after the JavaScript and CSS files are optimized, thus preventing the footer content from being optimized away.
@@ -74,6 +74,6 @@ export default {
7474

7575
:::warning
7676

77-
The footer content in DTS files is handled differently from JS/CSS files. It is written directly using the file system API, so setting `BannerPlugin` will not affect it.
77+
The footer content in DTS files is handled differently from JavaScript and CSS files. It is written directly using the file system API, so setting `BannerPlugin` will not affect it.
7878

7979
:::

website/docs/en/config/lib/format.mdx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
# lib.format
22

33
- **Type:** `'esm' | 'cjs' | 'umd' | 'mf'`
4-
54
- **Default:** `undefined`
6-
75
- **Required**: true
86

9-
Specify the output format for the generated JavaScript files.
7+
Specify the output format for the generated JavaScript output files.
108

119
See [Output Format](/guide/basic/output-format) and [Module Federation](/guide/advanced/module-federation) for more details.
1210

website/docs/en/config/lib/shims.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ const defaultShims = {
3434
};
3535
```
3636

37-
Configure the shims for CommonJS and ESM output.
37+
Configure the [shims](https://developer.mozilla.org/en-US/docs/Glossary/Shim) for CommonJS and ESM output.
3838

3939
## shims.cjs
4040

website/docs/en/config/lib/syntax.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export default {
4242

4343
## Set Browserslist Query
4444

45-
You can also set the Browserslist query, such as `last 2 versions`, `> 1%`, `node >= 16`, `chrome >= 80`, etc.
45+
You can also set the [Browserslist query](https://browsersl.ist/), such as `last 2 versions`, `> 1%`, `node >= 16`, `chrome >= 80`, etc.
4646

4747
```ts title="rslib.config.ts"
4848
export default {
@@ -56,7 +56,7 @@ export default {
5656

5757
## Mix ECMAScript Version and Browserslist Query
5858

59-
You can also mix ECMAScript version and Browserslist query, such as `es2015` and `node 20`. We will turn ECMAScript Version into Browserslist query, and then merge them together.
59+
You can also mix ECMAScript version and Browserslist query, such as `es2015` and `node 20`. Rslib will turn ECMAScript Version into Browserslist query, and then merge them together.
6060

6161
```ts title="rslib.config.ts"
6262
export default {
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,52 @@
11
# lib.autoExtension
2+
3+
- **类型:** `boolean`
4+
- **默认值:** `true`
5+
6+
是否根据 [`format`](/config/lib/format) 配置项自动设置 JavaScript 输出文件的扩展名。
7+
8+
## 默认扩展名
9+
10+
默认情况下,当 `autoExtension` 设置为 `true` 时,文件扩展名将会是:
11+
12+
-`package.json` 中设置 `type: module` 时,`esm` 格式使用 `.js``cjs` 格式使用 `.cjs`
13+
14+
-`package.json` 中设置 `type: commonjs` 或没有 `type` 字段时,`cjs` 格式使用 `.js``esm` 格式使用 `.mjs`
15+
16+
:::warning
17+
18+
[bundle](/config/lib/bundle) 设置为 `false`(即 bundleless 模式)时,你需要在源代码中写完整的路径,而不是省略目录索引(例如,用 `'./foo'` 作为 `'./foo/index.js'` 的简写)。
19+
20+
举例来说,如果 `foo` 是一个文件夹,你需要将 `import * from './foo'` 改写为 `import * from './foo/index'`
21+
22+
:::
23+
24+
`autoExtension` 设置为 `false` 时,文件扩展名将默认为 `.js`
25+
26+
## 自定义扩展名
27+
28+
你可以将 `autoExtension` 设置为 `false`,并使用 [output.filename](https://rsbuild.dev/zh/config/output/filename) 来自定义 JavaScript 输出文件。
29+
30+
```ts title="rslib.config.ts"
31+
export default defineConfig({
32+
lib: [
33+
{
34+
format: 'cjs',
35+
autoExtension: false,
36+
output: {
37+
filename: {
38+
js: '[name].cjs',
39+
},
40+
},
41+
},
42+
{
43+
format: 'esm',
44+
output: {
45+
filename: {
46+
js: '[name].mjs',
47+
},
48+
},
49+
},
50+
],
51+
});
52+
```

0 commit comments

Comments
 (0)