Skip to content

Commit c8329a6

Browse files
authored
docs: add options for cleanDistPath (#4381)
1 parent 5e24e7f commit c8329a6

File tree

5 files changed

+110
-8
lines changed

5 files changed

+110
-8
lines changed

packages/core/src/types/config.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -942,12 +942,14 @@ export type ManifestConfig = string | boolean | ManifestObjectConfig;
942942

943943
export type CleanDistPathObject = {
944944
/**
945-
* Whether to clean the dist path.
945+
* Whether to clean up all files under the output directory before the build starts.
946946
* @default 'auto'
947947
*/
948948
enable?: boolean | 'auto';
949949
/**
950-
* The files to keep in the dist path.
950+
* Specify the files to keep in the output directory.
951+
* If the file's absolute path matches the regular expression in `keep`, the file will not be removed.
952+
* @default undefined
951953
*/
952954
keep?: RegExp[];
953955
};
@@ -1009,7 +1011,7 @@ export interface OutputConfig {
10091011
*/
10101012
legalComments?: LegalComments;
10111013
/**
1012-
* Whether to clean all files in the dist path before starting compilation.
1014+
* Whether to clean up all files under the output directory before the build starts.
10131015
* @default 'auto'
10141016
*/
10151017
cleanDistPath?: CleanDistPath;

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

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
# output.cleanDistPath
22

3-
- **Type:** `boolean | 'auto'`
3+
- **Type:**
4+
5+
```ts
6+
type CleanDistPath = boolean | 'auto' | CleanDistPathObject;
7+
```
8+
49
- **Default:** `'auto'`
510

611
Whether to clean up all files under the output directory before the build starts (the output directory defaults to `dist`).
712

813
## Default behavior
914

10-
The default value of `output.cleanDistPath` is `'auto'`. If the output directory is a subdir of the project root path, Rsbuild will automatically clean all files under the build directory.
15+
The default value of `output.cleanDistPath` is `'auto'`. If the output directory is a subdir of the project root path, Rsbuild will automatically clean all files under the output directory.
1116

1217
When [output.distPath.root](/config/output/dist-path) is an external directory, or equals to the project root directory, `cleanDistPath` is not enabled by default, to avoid accidentally deleting files from other directories.
1318

@@ -44,3 +49,48 @@ export default {
4449
},
4550
};
4651
```
52+
53+
## Options
54+
55+
`output.cleanDistPath` supports configuration as an object to achieve more granular control.
56+
57+
### enable
58+
59+
- **Type:** `boolean | 'auto'`
60+
- **Default:** `'auto'`
61+
62+
Whether to clean up all files under the output directory before the build starts.
63+
64+
```js
65+
export default {
66+
output: {
67+
// Equivalent to `cleanDistPath: true`
68+
cleanDistPath: {
69+
enable: true,
70+
},
71+
},
72+
};
73+
```
74+
75+
### keep
76+
77+
- **Type:** `RegExp[]`
78+
- **Default:** `undefined`
79+
80+
Specify the files to keep in the output directory. If the file's absolute path matches the regular expression in `keep`, the file will not be removed.
81+
82+
For example, to keep the `dist/foo.json` file:
83+
84+
```js
85+
export default {
86+
output: {
87+
cleanDistPath: {
88+
keep: [/dist[\\/]foo.json/],
89+
},
90+
},
91+
};
92+
```
93+
94+
:::tip
95+
In the regular expression example, we use `[\\/]` to match the path separator because different operating systems use different path separators. Using `[\\/]` ensures that the paths can be matched in macOS, Linux and Windows.
96+
:::

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export default {
7070
The above two methods match the absolute paths of files using "path prefixes" and "regular expressions" respectively. It is worth noting that all referenced modules in the project will be matched. Therefore, you should avoid using overly loose values for matching to prevent compilation performance issues or compilation errors.
7171

7272
:::tip
73-
In the regular expression example above, we use `[\\/]` to match the path separator because different operating systems use different path separators. Using `[\\/]` ensures that the paths can be matched in macOS, Linux and Windows.
73+
In the regular expression example, we use `[\\/]` to match the path separator because different operating systems use different path separators. Using `[\\/]` ensures that the paths can be matched in macOS, Linux and Windows.
7474
:::
7575

7676
## Compile sub dependencies

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

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
# output.cleanDistPath
22

3-
- **类型:** `boolean | 'auto'`
3+
- **类型:**
4+
5+
```ts
6+
type CleanDistPath = boolean | 'auto' | CleanDistPathObject;
7+
```
8+
49
- **默认值:** `'auto'`
510

611
是否在构建开始前清理产物目录下的所有文件(产物目录默认为 `dist`)。
@@ -44,3 +49,48 @@ export default {
4449
},
4550
};
4651
```
52+
53+
## 选项
54+
55+
`output.cleanDistPath` 支持配置为对象,以实现更细粒度的控制。
56+
57+
### enable
58+
59+
- **类型:** `boolean | 'auto'`
60+
- **默认值:** `'auto'`
61+
62+
是否在构建开始前清理产物目录下的所有文件。
63+
64+
```js
65+
export default {
66+
output: {
67+
// 等价于 `cleanDistPath: true`
68+
cleanDistPath: {
69+
enable: true,
70+
},
71+
},
72+
};
73+
```
74+
75+
### keep
76+
77+
- **类型:** `RegExp[]`
78+
- **默认值:** `undefined`
79+
80+
指定在产物目录下保留的文件。如果文件的绝对路径可以匹配到 `keep` 中的正则表达式,则该文件不会被删除。
81+
82+
例如,保留 `dist/foo.json` 文件:
83+
84+
```js
85+
export default {
86+
output: {
87+
cleanDistPath: {
88+
keep: [/dist[\\/]foo.json/],
89+
},
90+
},
91+
};
92+
```
93+
94+
:::tip
95+
在正则表达式的例子中,我们使用 `[\\/]` 来匹配路径分隔符,这是因为不同的操作系统使用了不同的路径分隔符,使用 `[\\/]` 可以保证 macOS、Linux 和 Windows 的路径都被匹配到。
96+
:::

website/docs/zh/config/source/include.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export default {
7070
上述两种方法分别通过 "路径前缀" 和 "正则表达式" 来匹配文件的绝对路径,值得留意的是,项目中所有被引用的模块都会经过匹配,因此你不能使用过于松散的值进行匹配,避免造成编译性能问题或编译异常。
7171

7272
:::tip
73-
在上述正则表达式的例子中,我们使用 `[\\/]` 来匹配路径分隔符,这是因为不同的操作系统使用了不同的路径分隔符,使用 `[\\/]` 可以保证 macOS、Linux 和 Windows 的路径都被匹配到。
73+
在正则表达式的例子中,我们使用 `[\\/]` 来匹配路径分隔符,这是因为不同的操作系统使用了不同的路径分隔符,使用 `[\\/]` 可以保证 macOS、Linux 和 Windows 的路径都被匹配到。
7474
:::
7575

7676
## 编译间接依赖

0 commit comments

Comments
 (0)