Skip to content

Commit 4828c30

Browse files
authored
docs: improve output configuration (#4657)
1 parent ea877c4 commit 4828c30

File tree

7 files changed

+86
-46
lines changed

7 files changed

+86
-46
lines changed

packages/core/src/types/config.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,12 +1006,12 @@ export interface OutputConfig {
10061006
*/
10071007
externals?: Externals;
10081008
/**
1009-
* Set the directory of the dist files.
1010-
* Rsbuild will output files to the corresponding subdirectory according to the file type.
1009+
* Set the directory of the output files.
1010+
* Rsbuild will emit files to the specified subdirectory according to the file type.
10111011
*/
10121012
distPath?: DistPathConfig;
10131013
/**
1014-
* Sets the filename of dist files.
1014+
* Sets the filename of output files.
10151015
*/
10161016
filename?: FilenameConfig;
10171017
/**

website/docs/en/config/output/dist-path.mdx

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ type DistPathConfig = {
2525
const defaultDistPath = {
2626
root: 'dist',
2727
html: './',
28-
js: isServer ? '' : 'static/js',
29-
jsAsync: isServer ? '' : 'static/js/async',
28+
js: output.target === 'node' ? '' : 'static/js',
29+
jsAsync: output.target === 'node' ? '' : 'static/js/async',
3030
css: 'static/css',
3131
cssAsync: 'static/css/async',
3232
svg: 'static/svg',
@@ -38,9 +38,15 @@ const defaultDistPath = {
3838
};
3939
```
4040

41-
Set the directory of the dist files. Rsbuild will output files to the corresponding subdirectory according to the file type.
41+
Set the directory of the output files. Rsbuild will emit files to the specified subdirectory according to the file type.
4242

43-
Detail:
43+
> See [Output files](/guide/basic/output-files) for more information.
44+
45+
## File types
46+
47+
`output.distPath` can be set differently for different file types.
48+
49+
Here are the details of each `output.distPath` option:
4450

4551
- `root`: The root directory of all output files.
4652
- `html`: The output directory of HTML files.
@@ -55,19 +61,19 @@ Detail:
5561
- `media`: The output directory of media assets, such as videos.
5662
- `assets`: The output directory of other static assets. Such as the assets defined in [Extend Asset Types](/guide/basic/static-assets#extend-asset-types).
5763

58-
### Root directory
64+
## Root directory
5965

6066
The `root` is the root directory of the build artifacts and can be specified as a relative or absolute path. If the value of `root` is a relative path, it will be appended to the project's root directory to form an absolute path.
6167

6268
Other directories can only be specified as relative paths and will be output relative to the `root` directory.
6369

64-
### Example
70+
## Example
6571

6672
The JavaScript files will be output to the `distPath.root` + `distPath.js` directory, which is `dist/static/js`.
6773

6874
To output JavaScript files to the `build/resource/js` directory, add the following config:
6975

70-
```js
76+
```ts title="rsbuild.config.ts"
7177
export default {
7278
output: {
7379
distPath: {
@@ -77,3 +83,13 @@ export default {
7783
},
7884
};
7985
```
86+
87+
The above config will generate the following directory structure:
88+
89+
```bash
90+
build
91+
├── resource
92+
│ └── js
93+
│ └── index.js
94+
└── index.html
95+
```

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,15 @@ const prodDefaultFilename = {
4343
};
4444
```
4545

46-
Sets the filename of dist files.
46+
Sets the filename of output files.
4747

4848
After the production build, Rsbuild will add a hash in the middle of the filename by default. If you don't need to add it, you can set [output.filenameHash](/config/output/filename-hash) to `false` to disable this behavior.
4949

50-
The following are the details of each filename:
50+
## File types
51+
52+
`output.filename` can be set differently for different file types.
53+
54+
Here are the details of each `output.filename` option:
5155

5256
- `html`: The name of the HTML files.
5357
- `js`: The name of the JavaScript files.
@@ -58,7 +62,7 @@ The following are the details of each filename:
5862
- `media`: The name of media assets, such as video.
5963
- `assets`: The name of other static assets. Such as the assets defined in [Extend Asset Types](/guide/basic/static-assets#extend-asset-types).
6064

61-
> See [Output Files](/guide/basic/output-files) for more information.
65+
> See [Output files](/guide/basic/output-files) for more information.
6266
6367
## Example
6468

website/docs/en/guide/basic/output-files.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ export default {
9797
};
9898
```
9999

100-
The above config produces the following directory structure:
100+
The above config will generate the following directory structure:
101101

102102
```bash
103103
dist
@@ -161,7 +161,7 @@ export default {
161161
};
162162
```
163163

164-
The above config produces the following directory structure:
164+
The above config will generate the following directory structure:
165165

166166
```bash
167167
dist

website/docs/zh/config/output/dist-path.mdx

Lines changed: 36 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ type DistPathConfig = {
2525
const defaultDistPath = {
2626
root: 'dist',
2727
html: './',
28-
js: isServer ? '' : 'static/js',
29-
jsAsync: isServer ? '' : 'static/js/async',
28+
js: output.target === 'node' ? '' : 'static/js',
29+
jsAsync: output.target === 'node' ? '' : 'static/js/async',
3030
css: 'static/css',
3131
cssAsync: 'static/css/async',
3232
svg: 'static/svg',
@@ -38,36 +38,42 @@ const defaultDistPath = {
3838
};
3939
```
4040

41-
设置构建产物的输出目录,Rsbuild 会根据产物的类型输出到对应的子目录下。
42-
43-
其中:
44-
45-
- `root`: 表示所有构建产物输出的根目录。
46-
- `html`:表示 HTML 文件的输出目录。
47-
- `js`:表示 JavaScript 文件的输出目录。
48-
- `jsAsync`:表示异步 JavaScript 文件的输出目录,默认会输出到 `distPath.js``async` 子目录。
49-
- `css`:表示 CSS 文件的输出目录。
50-
- `cssAsync`:表示异步 CSS 文件的输出目录,默认会输出到 `distPath.css``async` 子目录。
51-
- `svg`:表示 SVG 图片的输出目录。
52-
- `font`:表示字体文件的输出目录。
53-
- `wasm`:表示 WebAssembly 文件的输出目录。
54-
- `image`:表示非 SVG 图片的输出目录。
55-
- `media`:表示视频等媒体资源的输出目录。
41+
设置构建产物的输出目录,Rsbuild 会根据产物的类型将其输出到相应的子目录中。
42+
43+
> 查看 [构建产物目录](/guide/basic/output-files) 了解更多。
44+
45+
## 文件类型
46+
47+
`output.distPath` 可以为不同类型的文件设置不同的输出目录。
48+
49+
下面是 `output.distPath` 中各个选项的说明:
50+
51+
- `root`: 所有构建产物输出的根目录。
52+
- `html`:HTML 文件的输出目录。
53+
- `js`:JavaScript 文件的输出目录。
54+
- `jsAsync`:异步 JavaScript 文件的输出目录,默认会输出到 `distPath.js``async` 子目录。
55+
- `css`:CSS 文件的输出目录。
56+
- `cssAsync`:异步 CSS 文件的输出目录,默认会输出到 `distPath.css``async` 子目录。
57+
- `svg`:SVG 图片的输出目录。
58+
- `font`:字体文件的输出目录。
59+
- `wasm`:WebAssembly 文件的输出目录。
60+
- `image`:非 SVG 图片的输出目录。
61+
- `media`:视频等媒体资源的输出目录。
5662
- `assets`:其他静态资源的输出目录。例如 [扩展静态资源类型](/guide/basic/static-assets#扩展静态资源类型) 中定义的资源。
5763

58-
### 根目录
64+
## 根目录
5965

6066
`root` 是构建产物的根目录,可以为相对路径或绝对路径。如果 `root` 的值为相对路径,则会基于当前项目的根目录拼接为绝对路径。
6167

6268
其他目录只能为相对路径,并且会相对于 `root` 进行输出。
6369

64-
### 示例
70+
## 示例
6571

6672
以 JavaScript 文件为例,会输出到 `distPath.root` + `distPath.js` 目录,即为 `dist/static/js`
6773

6874
如果需要将 JavaScript 文件输出到 `build/resource/js` 目录,可以这样设置:
6975

70-
```js
76+
```ts title="rsbuild.config.ts"
7177
export default {
7278
output: {
7379
distPath: {
@@ -77,3 +83,13 @@ export default {
7783
},
7884
};
7985
```
86+
87+
以上配置会生成如下的目录结构:
88+
89+
```bash
90+
build
91+
├── resource
92+
│ └── js
93+
│ └── index.js
94+
└── index.html
95+
```

website/docs/zh/config/output/filename.mdx

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,19 @@ const prodDefaultFilename = {
4747

4848
在生产模式构建后,Rsbuild 会自动在文件名中间添加 hash 值,如果不需要添加,可以将 [output.filenameHash](/config/output/filename-hash) 设置为 `false` 来禁用该行为。
4949

50-
下面是各个文件类型的说明:
51-
52-
- `html`:表示 HTML 文件的名称。
53-
- `js`:表示 JavaScript 文件的名称。
54-
- `css`:表示 CSS 样式文件的名称。
55-
- `svg`:表示 SVG 图片的名称。
56-
- `font`:表示字体文件的名称。
57-
- `image`:表示非 SVG 图片的名称。
58-
- `media`:表示视频等媒体资源的名称。
50+
## 文件类型
51+
52+
`output.filename` 可以为不同类型的文件设置不同的名称。
53+
54+
下面是 `output.filename` 中各个选项的说明:
55+
56+
- `html`:HTML 文件的名称。
57+
- `js`:JavaScript 文件的名称。
58+
- `css`:CSS 样式文件的名称。
59+
- `svg`:SVG 图片的名称。
60+
- `font`:字体文件的名称。
61+
- `image`:非 SVG 图片的名称。
62+
- `media`:视频等媒体资源的名称。
5963
- `assets`:其他静态资源的名称。例如 [扩展静态资源类型](/guide/basic/static-assets#扩展静态资源类型) 中定义的资源。
6064

6165
> 查看 [构建产物目录](/guide/basic/output-files) 了解更多。

website/docs/zh/guide/basic/output-files.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ export default {
9797
};
9898
```
9999

100-
上方的配置会生成以下目录结构
100+
以上配置会生成如下的目录结构
101101

102102
```bash
103103
dist
@@ -161,7 +161,7 @@ export default {
161161
};
162162
```
163163

164-
上方的配置会生成以下目录结构
164+
以上配置会生成如下的目录结构
165165

166166
```bash
167167
dist

0 commit comments

Comments
 (0)