Skip to content

Commit 0fc2cf3

Browse files
authored
docs: update terminology and improve clarity in optimization and devtool (#10581)
* docs: update terminology and improve clarity in optimization and devtool * docs: fix link
1 parent e32b7ed commit 0fc2cf3

File tree

14 files changed

+139
-111
lines changed

14 files changed

+139
-111
lines changed

website/docs/en/config/devtool.mdx

Lines changed: 24 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -32,28 +32,28 @@ type Devtool = 'string' | false;
3232
- Extremely fast build speed
3333
- **Full source code mapping needed** → Proceed to [Step 3](#step-3-configure-sourcemap)
3434

35-
### Step 3: Configure SourceMap
35+
### Step 3: Configure source map
3636

37-
Set `devtool: 'source-map'`, A full SourceMap is emitted as a separate file. It adds a `//# sourceMapURL` comment to the bundle so development tools know where to find it.
37+
Set `devtool: 'source-map'`, A full source map is emitted as a separate file. It adds a `//# sourceMapURL` comment to the bundle so development tools know where to find it.
3838

39-
It also supports combination with the following modifiers to improve performance and control SourceMap generation.
39+
It also supports combination with the following modifiers to improve performance and control source map generation.
4040

4141
Performance optimization modifiers, to speed up the build, usually used in development environments:
4242

43-
| Modifier | Effect | Performance improvement |
44-
| -------- | -------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------- |
45-
| eval | Each module is executed with `eval()` and a SourceMap is added as a DataUrl to the `eval()`, avoiding chunk-level multiple SourceMap concate | ⚡⚡⚡ |
46-
| cheap | Maps line numbers only (no columns), ignores source maps from loaders | ⚡⚡ |
47-
| module | Processes source maps from loaders to map to original code (line-only mapping) ||
43+
| Modifier | Effect | Performance improvement |
44+
| -------- | ---------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------- |
45+
| eval | Each module is executed with `eval()` and a source map is added as a DataUrl to the `eval()`, avoiding chunk-level multiple source map concate | ⚡⚡⚡ |
46+
| cheap | Maps line numbers only (no columns), ignores source maps from loaders | ⚡⚡ |
47+
| module | Processes source maps from loaders to map to original code (line-only mapping) ||
4848

49-
Functional modifiers, to control SourceMap generation, usually used in production environments:
49+
Functional modifiers, to control source map generation, usually used in production environments:
5050

51-
| Modifier | Effect |
52-
| --------- | ------------------------------------------------------------------------------------------------------------------------------------------- |
53-
| hidden | SourceMap is emitted as a separate file, but no `//# sourceMappingURL=[url]` comment is added to the bundle, protecting source code privacy |
54-
| inline | SourceMap is added as a DataUrl to the bundle |
55-
| nosources | SourceMap is created without the `sourcesContent` in it |
56-
| debugids | SourceMap is created with the `debugId` in it |
51+
| Modifier | Effect |
52+
| --------- | -------------------------------------------------------------------------------------------------------------------------------------------- |
53+
| hidden | source map is emitted as a separate file, but no `//# sourceMappingURL=[url]` comment is added to the bundle, protecting source code privacy |
54+
| inline | source map is added as a DataUrl to the bundle |
55+
| nosources | source map is created without the `sourcesContent` in it |
56+
| debugids | source map is created with the `debugId` in it |
5757

5858
We expect a certain pattern when validate devtool name, pay attention and don't mix up the sequence of devtool string. The pattern is: `[inline-|hidden-|eval-][nosources-][cheap-[module-]]source-map[-debugids]`.
5959

@@ -63,34 +63,26 @@ We expect a certain pattern when validate devtool name, pay attention and don't
6363

6464
The following options are ideal for development:
6565

66-
`eval` - Each module is executed with `eval()` and `//# sourceURL`. This is pretty fast. The main disadvantage is that it doesn't display line numbers correctly since it gets mapped to transpiled code instead of the original code (No Source Maps from Loaders).
66+
`eval` - Each module is executed with `eval()` and `//# sourceURL`. This is pretty fast. The main disadvantage is that it doesn't display line numbers correctly since it gets mapped to transpiled code instead of the original code (No source maps from Loaders).
6767

68-
`eval-source-map` - Each module is executed with `eval()` and a SourceMap is added as a DataUrl to the `eval()`. Initially it is slow, but it provides fast rebuild speed and yields real files. Line numbers are correctly mapped since it gets mapped to the original code. It yields the best quality SourceMaps for development.
68+
`eval-source-map` - Each module is executed with `eval()` and a source map is added as a DataUrl to the `eval()`. Initially it is slow, but it provides fast rebuild speed and yields real files. Line numbers are correctly mapped since it gets mapped to the original code. It yields the best quality source maps for development.
6969

70-
`eval-cheap-source-map` - Similar to `eval-source-map`, each module is executed with `eval()`. It is "cheap" because it doesn't have column mappings, it only maps line numbers. It ignores SourceMaps from Loaders and only display transpiled code similar to the eval devtool.
70+
`eval-cheap-source-map` - Similar to `eval-source-map`, each module is executed with `eval()`. It is "cheap" because it doesn't have column mappings, it only maps line numbers. It ignores source maps from Loaders and only display transpiled code similar to the eval devtool.
7171

72-
`eval-cheap-module-source-map` - Similar to `eval-cheap-source-map`, however, in this case Source Maps from Loaders are processed for better results. However Loader Source Maps are simplified to a single mapping per line.
72+
`eval-cheap-module-source-map` - Similar to `eval-cheap-source-map`, however, in this case source maps from Loaders are processed for better results. However Loader source maps are simplified to a single mapping per line.
7373

7474
### Production
7575

7676
These options are typically used in production:
7777

78-
'false' - No SourceMap is emitted. This is a good option to start with.
78+
'false' - No source map is emitted. This is a good option to start with.
7979

80-
`source-map` - A full SourceMap is emitted as a separate file. It adds a reference comment to the bundle so development tools know where to find it.
80+
`source-map` - A full source map is emitted as a separate file. It adds a reference comment to the bundle so development tools know where to find it.
8181

82-
:::warning
83-
You should configure your server to disallow access to the Source Map file for normal users!
84-
:::
85-
86-
`hidden-source-map` - Same as `source-map`, but doesn't add a reference comment to the bundle. Useful if you only want SourceMaps to map error stack traces from error reports, but don't want to expose your SourceMap for the browser development tools.
87-
88-
:::warning
89-
You should not deploy the Source Map file to the webserver. Instead only use it for error report tooling.
90-
:::
82+
`hidden-source-map` - Same as `source-map`, but doesn't add a reference comment to the bundle. Useful if you only want source maps to map error stack traces from error reports, but don't want to expose your source map for the browser development tools.
9183

92-
`nosources-source-map` - A SourceMap is created without the `sourcesContent` in it. It can be used to map stack traces on the client without exposing all of the source code. You can deploy the Source Map file to the webserver.
84+
`nosources-source-map` - A source map is created without the `sourcesContent` (the original source code) in it. It still exposes the original filenames and structure and can be used to map stack traces on the client without exposing the source code. This kind of source map can be deployed to the web server if you can accept the file name being exposed.
9385

9486
:::warning
95-
It still exposes original filenames and structure, but it doesn't expose the original code.
87+
When using `source-map` or `hidden-source-map`, do not deploy the source maps (`.map` file) to the public web server or CDN. Public source maps will expose your source code and may bring security risks.
9688
:::

website/docs/en/config/optimization.mdx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,14 @@ Here we assign the `value` to `value2`. Both `value2` and `value` are accessed w
427427

428428
Tells Rspack to find segments of the module graph which can be safely concatenated into a single module. Depends on [optimization.providedExports](#optimizationprovidedexports) and [optimization.usedExports](#optimizationusedexports). By default `optimization.concatenateModules` is enabled in `production` mode and disabled elsewise.
429429

430+
```js title="rspack.config.mjs"
431+
export default {
432+
optimization: {
433+
concatenateModules: false,
434+
},
435+
};
436+
```
437+
430438
## optimization.nodeEnv
431439

432440
<PropertyType

website/docs/en/guide/optimization/analysis.mdx

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,8 @@
11
# Bundle analysis
22

3-
## webpack-bundle-analyzer
4-
5-
Rspack's Command Line Interface (CLI) supports bundle analysis out-of-box via the `--analyze` option. It uses [webpack-bundle-analyzer](https://www.npmjs.com/package/webpack-bundle-analyzer) behind the scenes.
6-
7-
```sh
8-
$ rspack build --analyze
9-
```
10-
11-
## bundle-stats and statoscope
12-
13-
You can also generate a `stats.json` file for further analysis with other bundle analysis tools like [bundle-stats](https://github.com/relative-ci/bundle-stats) or [statoscope](https://statoscope.tech/):
14-
15-
```sh
16-
$ rspack build --json stats.json
17-
```
18-
193
## Rsdoctor's bundle analysis
204

21-
Rsdoctor provides the `Bundle Size` module, which is mainly used to analyze the information of the outputs of Rspack, including the size of resources, duplicate packages, and module reference relationships:
5+
[Rsdoctor](/guide/optimization/use-rsdoctor) provides the `Bundle Size` module, which is mainly used to analyze the information of the outputs of Rspack, including the size of resources, duplicate packages, and module reference relationships:
226

237
- **Bundle Overview**: Displays the total number and size of artifacts, as well as the number and size of each file type. It also shows the duplicate packages and their reference chains.
248
- **Bundle Analysis Module**: Analyzes the size and code information of the build artifacts' resources (**Assets**) and the included **Modules**. In this module, you can view the **actual code size of modules after packaging** in the Assets, as well as the original code or **packaged code segments** and **module reference relationships**.
@@ -44,3 +28,19 @@ You can use [Rsdoctor](https://rsdoctor.rs) to detect whether there are duplicat
4428
![](https://assets.rspack.rs/others/assets/rsdoctor/overall-alerts.jpg)
4529

4630
For more details, see [Rsdoctor - Duplicate Dependency Problem](https://rsdoctor.rs/blog/topic/duplicate-pkg-problem).
31+
32+
## webpack-bundle-analyzer
33+
34+
Rspack's Command Line Interface (CLI) supports bundle analysis out-of-box via the `--analyze` option. It uses [webpack-bundle-analyzer](https://www.npmjs.com/package/webpack-bundle-analyzer) behind the scenes.
35+
36+
```sh
37+
$ rspack build --analyze
38+
```
39+
40+
## bundle-stats and statoscope
41+
42+
You can also generate a `stats.json` file for further analysis with other bundle analysis tools like [bundle-stats](https://github.com/relative-ci/bundle-stats) or [statoscope](https://statoscope.tech/):
43+
44+
```sh
45+
$ rspack build --json stats.json
46+
```

website/docs/en/guide/optimization/production.mdx

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,22 @@
1-
# Production
1+
# Production optimization
22

3-
## Source mapping
3+
## Code splitting
44

5-
It is recommended to enable SourceMap for production environments to facilitate debugging in production environments. If you have a large project, it is recommended that you choose a configuration with better performance (see [devtool](config/devtool) for more options), such as the `source-map` configuration option.
5+
Rspack supports code splitting, which allows splitting the code into other chunks. You have the full control about size and number of generated assets, which allow you to gain performance improvements in loading time.
6+
7+
See [Code splitting](/guide/optimization/code-splitting) for more details.
8+
9+
## Tree shaking
10+
11+
Rspack supports tree shaking, a terminology widely used within the JavaScript ecosystem defined as the removal of unused code, commonly referred to as "dead code".
12+
13+
See [Tree shaking](/guide/optimization/tree-shaking) for more details.
614

715
## Minification
816

9-
During the production build, Rspack uses the built-in minimizer to minify JavaScript and CSS code by default. You can use [SwcJsMinimizerRspackPlugin](/plugins/rspack/swc-js-minimizer-rspack-plugin) and [LightningCssMinimizerRspackPlugin](/plugins/rspack/lightning-css-minimizer-rspack-plugin) for configuration.
17+
During the production build, Rspack uses the built-in minimizer to minify JavaScript and CSS code by default.
18+
19+
If you need to customize the minification options, you can use [SwcJsMinimizerRspackPlugin](/plugins/rspack/swc-js-minimizer-rspack-plugin) and [LightningCssMinimizerRspackPlugin](/plugins/rspack/lightning-css-minimizer-rspack-plugin) for configuration.
1020

1121
```js title="rspack.config.mjs"
1222
import { rspack } from '@rspack/core';

website/docs/en/guide/optimization/tree-shaking.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Tree shaking
22

3-
Rspack supports [tree shaking](https://developer.mozilla.org/en-US/docs/Glossary/Tree_shaking), a terminology widely used within the JavaScript ecosystem defined as the removal of unused code, commonly referred to as "dead code." Dead code arises when certain exports from a module are not used and they lack side effects, allowing such pieces to be safely deleted to reduce the final output size.
3+
Rspack supports [tree shaking](https://developer.mozilla.org/en-US/docs/Glossary/Tree_shaking), a terminology widely used within the JavaScript ecosystem defined as the removal of unused code, commonly referred to as "dead code". Dead code arises when certain exports from a module are not used and they lack side effects, allowing such pieces to be safely deleted to reduce the final output size.
44

55
## What is tree shaking
66

website/docs/zh/blog/announcing-1-3.mdx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Rspack 1.3 已经正式发布!
2121
- [Lazy compilation 改进](#lazy-compilation-改进)
2222
- [支持 AMD 模块](#支持-amd-模块)
2323
- 性能优化
24-
- [代码拆分提速 25%](#代码拆分提速-25)
24+
- [代码分割提速 25%](#代码分割提速-25)
2525
- [产物体积优化](#产物体积优化)
2626
- [内存优化](#内存优化)
2727
- Rstack 进展
@@ -130,11 +130,11 @@ export default {
130130
131131
## 性能优化
132132

133-
### 代码拆分提速 25%
133+
### 代码分割提速 25%
134134

135-
在 Rspack 1.2 中,我们引入了 [experiments.parallelCodeSplitting](/config/experiments#experimentsparallelcodesplitting) 选项来开启新版的代码拆分算法
135+
在 Rspack 1.2 中,我们引入了 [experiments.parallelCodeSplitting](/config/experiments#experimentsparallelcodesplitting) 选项来开启新版的代码分割算法
136136

137-
从 Rspack 1.3 开始,该选项已经默认开启,并使代码拆分的速度提升 **25%**
137+
从 Rspack 1.3 开始,该选项已经默认开启,并使代码分割的速度提升 **25%**
138138

139139
### 产物体积优化
140140

0 commit comments

Comments
 (0)