Skip to content

Commit

Permalink
feat: add output.sourceMap doc
Browse files Browse the repository at this point in the history
  • Loading branch information
caohuilin committed Sep 12, 2024
1 parent 1b5f481 commit 41fc818
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 80 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,44 +26,6 @@ const defaultDisableSourceMap = {

Whether to disable Source Map generation.

:::tip What is a Source Map
Source Map is an information file that saves the source code mapping relationship. It records each location of the compiled code and the corresponding pre-compilation location. With Source Map, you can directly view the source code when debugging the compiled code.
:::warning
**Deprecated**: This configuration is deprecated, please use the boolean usage of `output.sourceMap` instead.
:::

By default, Builder's Source Map generation rules are:

- In development build, SourceMap of JS files and CSS files will be generated, which is convenient for debugging.
- In production build, the Source Map of JS files will be generated for debugging and troubleshooting online problems; the Source Map of CSS files will not be generated.

If the project does not need Source Map, you can turned off it to speed up the compile speed.

```js
export default {
output: {
disableSourceMap: true,
},
};
```

If you want to enable Source Map in development and disable it in the production, you can set to:

```js
export default {
output: {
disableSourceMap: process.env.NODE_ENV === 'production',
},
};
```

If you need to individually control the Source Map of JS files or CSS files, you can refer to the following settings:

```js
export default {
output: {
disableSourceMap: {
js: false,
css: true,
},
},
};
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
title: sourceMap
configName: output.sourceMap
---

# output.sourceMap

- **Type:**

```ts
type SourceMap = {
js?: Rspack.Configuration['devtool'];
css?: boolean;
};
```

- **Default:**

```ts
const defaultSourceMap = {
js: isDev ? 'cheap-module-source-map' : false,
css: false,
};
```

Used to set whether to generate source map files, and which format of source map to generate.

import RsbuildConig from '@site-docs-en/components/rsbuild-config-tooltip';

<RsbuildConig />
Original file line number Diff line number Diff line change
Expand Up @@ -26,44 +26,6 @@ const defaultDisableSourceMap = {

是否禁用 Source Map 生成。

:::tip 什么是 Source Map
Source Map 是保存源代码映射关系的信息文件,它记录了编译后的代码的每一个位置,以及所对应的编译前的位置。通过 Source Map,可以在调试编译后的代码时,直接查看对应的源代码
:::warning
**Deprecated**:该配置已废弃,请使用 `output.sourceMap` 的布尔用法代替
:::

默认情况下,Builder 的 Source Map 生成规则如下:

- 在开发环境构建时,会生成 JS 文件和 CSS 文件的 SourceMap,便于进行开发调试。
- 在生产环境构建时,会生成 JS 文件的 Source Map,用于调试和排查线上问题;不会生成 CSS 文件的 Source Map。

如果项目不需要 Source Map,可以关闭该功能,从而提升构建的速度。

```js
export default {
output: {
disableSourceMap: true,
},
};
```

如果需要开启开发环境的 Source Map,并在生产环境禁用,可以设置为:

```js
export default {
output: {
disableSourceMap: process.env.NODE_ENV === 'production',
},
};
```

如果需要单独控制 JS 文件或 CSS 文件的 Source Map,可以参考下方设置:

```js
export default {
output: {
disableSourceMap: {
js: false,
css: true,
},
},
};
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
title: sourceMap
configName: output.sourceMap
---

# output.sourceMap

- **类型:**

```ts
type SourceMap = {
js?: Rspack.Configuration['devtool'];
css?: boolean;
};
```

- **默认值:**

```ts
const defaultSourceMap = {
js: isDev ? 'cheap-module-source-map' : false,
css: false,
};
```

用于设置是否生成 source map 文件,以及生成哪一种格式的 source map。

import RsbuildConig from '@site-docs/components/rsbuild-config-tooltip';

<RsbuildConig />

0 comments on commit 41fc818

Please sign in to comment.