Skip to content

Commit 14aa4e6

Browse files
committed
up
1 parent eeafd6c commit 14aa4e6

File tree

2 files changed

+62
-4
lines changed

2 files changed

+62
-4
lines changed

website/docs/en/guide/faq/features.mdx

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
# Features FAQ
22

3-
## How to preserve all comments in the output files?
3+
## Code Minification
4+
5+
### How to preserve all comments in the output files?
46

57
By default, Rslib uses SWC to remove comments. The corresponding SWC [jsc.minify.format](https://swc.rs/docs/configuration/minification#jscminifyformat) configuration is
68

79
```js
810
{
9-
comments: 'some', //
11+
comments: 'some',
1012
preserveAnnotations: true,
1113
}
1214
```
@@ -15,6 +17,9 @@ This will only preserve some legal comments and annotations. If you want to pres
1517

1618
```ts title="rslib.config.ts"
1719
export default {
20+
lib: [
21+
// ...
22+
],
1823
output: {
1924
minify: {
2025
jsOptions: {
@@ -28,3 +33,27 @@ export default {
2833
},
2934
};
3035
```
36+
37+
### How to compress the output size while preserving code readability?
38+
39+
Compressing code can reduce the output size and improve loading speed, but the compressed code is less readable and harder to debug. If you want to preserve code readability, you can keep variable names and disable compression to facilitate debugging. Refer to [web-infra-dev/rsbuild#966](https://github.com/web-infra-dev/rsbuild/pull/3966).
40+
41+
```ts title="rslib.config.ts"
42+
export default {
43+
lib: [
44+
// ...
45+
],
46+
output: {
47+
minify: {
48+
jsOptions: {
49+
minimizerOptions: {
50+
// preserve variable name and disable minify for easier debugging
51+
mangle: false,
52+
minify: false,
53+
compress: true,
54+
},
55+
},
56+
},
57+
},
58+
};
59+
```

website/docs/zh/guide/faq/features.mdx

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
# 功能类问题
22

3-
## 如何保留产物文件代码中的注释?
3+
## 代码压缩
4+
5+
### 如何保留产物文件代码中的注释?
46

57
默认情况下,Rslib 使用 SWC 清除注释,对应的 SWC 的 [jsc.minify.format](https://swc.rs/docs/configuration/minification#jscminifyformat) 配置为
68

79
```js
810
{
9-
comments: 'some', //
11+
comments: 'some',
1012
preserveAnnotations: true,
1113
}
1214
```
@@ -15,6 +17,9 @@
1517

1618
```ts title="rslib.config.ts"
1719
export default {
20+
lib: [
21+
// ...
22+
],
1823
output: {
1924
minify: {
2025
jsOptions: {
@@ -28,3 +33,27 @@ export default {
2833
},
2934
};
3035
```
36+
37+
### 如何在保留代码可读性的同时,尽可能压缩产物体积?
38+
39+
通过压缩代码可以减小产物体积,并提高加载速度,但是压缩后的代码可读性较差,不利于调试。如果你想保留代码可读性,可以通过如下配置,保留变量名并禁用压缩以方便调试。参考 [web-infra-dev/rsbuild#966](https://github.com/web-infra-dev/rsbuild/pull/3966).
40+
41+
```ts title="rslib.config.ts"
42+
export default {
43+
lib: [
44+
// ...
45+
],
46+
output: {
47+
minify: {
48+
jsOptions: {
49+
minimizerOptions: {
50+
// 保留变量名并禁用压缩以方便调试
51+
mangle: false,
52+
minify: false,
53+
compress: true,
54+
},
55+
},
56+
},
57+
},
58+
};
59+
```

0 commit comments

Comments
 (0)