Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 39 additions & 9 deletions website/docs/en/config/optimization.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -192,23 +192,53 @@ Here we assign the `value` to `value2`. Both `value2` and `value` are accessed w
## optimization.mangleExports

<PropertyType
type="boolean | 'deterministic' | 'size' "
type="boolean | 'deterministic' | 'size'"
defaultValueList={[
{ defaultValue: 'deterministic', mode: 'production' },
{ defaultValue: 'true', mode: 'production' },
{ defaultValue: 'false', mode: 'development' },
]}
/>

`optimization.mangleExports` allows to control export mangling.
`optimization.mangleExports` controls how export names are mangled.

The following values are supported:

| option | description |
| --------------- | ---------------------------------------------------------------------------------------------------------------------------------- |
| 'named' | Use meaningful, easy-to-debug content as id. This option is enabled by default in development mode |
| 'deterministic' | Use the hashed module identifier as the id to benefit from long-term caching. This option is enabled by default in production mode |
| true | Same as 'deterministic' |
| false | Keep original name. Good for readability and debugging. |
| option | description |
| ----------------- | -------------------------------------------------------------------------------------------------------------- |
| `'size'` | Use the shortest possible export names to reduce bundle size. |
| `'deterministic'` | Use short and stable export names for better long-term cache stability. Enabled by default in production mode. |
| `true` | Same as `'deterministic'`. |
| `false` | Disable export mangling and keep original export names. Enabled by default in development mode. |

For example, with the following source code:

```js title="src/math.js"
export const veryLongExportName = 1;
```

When `mangleExports` is disabled, the export name is preserved:

```js title="dist/main.js"
__webpack_require__.d(__webpack_exports__, {
veryLongExportName: () => veryLongExportName,
});
```

When `mangleExports` is set to `'size'`, the export name is shortened:

```js title="rspack.config.mjs"
export default {
optimization: {
mangleExports: 'size',
},
};
```

```js title="dist/main.js"
__webpack_require__.d(__webpack_exports__, {
a: () => veryLongExportName,
});
```

## optimization.mergeDuplicateChunks

Expand Down
4 changes: 2 additions & 2 deletions website/docs/en/config/performance.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ You can define budget thresholds with `maxAssetSize` and `maxEntrypointSize`, an

<PropertyType type="false | object" />

Set `performance` to `false` to disable the performance hint:
Set `performance` to `false` to disable the performance hints:

```js title="rspack.config.mjs"
export default {
Expand Down Expand Up @@ -85,7 +85,7 @@ export default {

<PropertyType type="number" defaultValueList={[{ defaultValue: '250000' }]} />

Sets the total size threshold for an entrypoint (in bytes). Entrypoint size means the total size needed for the initial load of that entry. Rspack emits a performance hint when the entrypoint total size exceeds this value.
Sets the total size threshold for an entrypoint (in bytes). Entrypoint total size means the total size needed for the initial load of that entry. Rspack emits a performance hint when the entrypoint total size exceeds this value.

For example, set the entrypoint size threshold to 500 KB:

Expand Down
48 changes: 39 additions & 9 deletions website/docs/zh/config/optimization.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -192,23 +192,53 @@ function f2() {
## optimization.mangleExports

<PropertyType
type="boolean | 'deterministic' | 'size' "
type="boolean | 'deterministic' | 'size'"
defaultValueList={[
{ defaultValue: 'deterministic', mode: 'production' },
{ defaultValue: 'true', mode: 'production' },
{ defaultValue: 'false', mode: 'development' },
]}
/>

`optimization.mangleExports` 允许控制导出名称的混淆
`optimization.mangleExports` 用于控制导出名的混淆方式

支持以下选项:

| option | description |
| --------------- | ---------------------------------------------------------------------------------- |
| 'named' | 使用有意义且易于调试的内容作为标识符。在开发模式下,默认启用此选项。 |
| 'deterministic' | 使用哈希模块标识符作为标识符,以便从长期缓存中受益。在生产模式下,默认启用此选项。 |
| true | 与 'deterministic' 相同。 |
| false | 保留原始名称。适用于可读性和调试。 |
| option | description |
| ----------------- | -------------------------------------------------------------------------- |
| `'size'` | 使用尽可能短的导出名,以减小产物体积。 |
| `'deterministic'` | 使用短且稳定的导出名,以获得更好的长期缓存稳定性。生产模式默认启用该选项。 |
| `true` | 与 `'deterministic'` 相同。 |
| `false` | 关闭导出名混淆,保留原始导出名。开发模式默认启用该选项。 |

例如源代码为:

```js title="src/math.js"
export const veryLongExportName = 1;
```

关闭 `mangleExports` 时,导出名会被保留:

```js title="dist/main.js"
__webpack_require__.d(__webpack_exports__, {
veryLongExportName: () => veryLongExportName,
});
```

将 `mangleExports` 设置为 `'size'` 时,导出名会被缩短:

```js title="rspack.config.mjs"
export default {
optimization: {
mangleExports: 'size',
},
};
```

```js title="dist/main.js"
__webpack_require__.d(__webpack_exports__, {
a: () => veryLongExportName,
});
```

## optimization.mergeDuplicateChunks

Expand Down
4 changes: 2 additions & 2 deletions website/docs/zh/config/performance.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ export default {

<PropertyType type="number" defaultValueList={[{ defaultValue: '250000' }]} />

设置入口总体积阈值(单位:bytes)。入口体积指首屏加载该入口时需要的总体积。当入口总体积超过该值时,Rspack 会触发性能提示。
设置入口总体积阈值(单位:bytes)。这里的入口总体积指初始加载该入口时需要的所有资源总体积,当入口总体积超过该值时,Rspack 会触发性能提示。

例如设置入口体积阈值为 500 KB:
例如设置入口总体积阈值为 500 KB:

```js title="rspack.config.mjs"
export default {
Expand Down
Loading