Skip to content

Commit b08bb4c

Browse files
authored
docs: add dev.browserLogs config (#6287)
1 parent bc42a00 commit b08bb4c

File tree

3 files changed

+77
-1
lines changed

3 files changed

+77
-1
lines changed

packages/core/src/types/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1720,7 +1720,7 @@ export type WriteToDisk = boolean | ((filename: string) => boolean);
17201720

17211721
export interface DevConfig {
17221722
/**
1723-
* Enables forwarding of browser runtime errors to the terminal. When `true`, the dev
1723+
* Controls whether to forward browser runtime errors to the terminal. When `true`, the dev
17241724
* client listens for window `error` events in the browser and send them to the dev server,
17251725
* where they are printed in the terminal (prefixed with `[browser]`).
17261726
* @default true
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# dev.browserLogs
2+
3+
- **Type:** `boolean`
4+
- **Default:** `true`
5+
- **Version:** Added in v1.5.13
6+
7+
Controls whether to forward browser runtime errors to the terminal.
8+
9+
When `true`, the Rsbuild client listens for window `error` events in the browser and send them to the dev server, where they are printed in the terminal (prefixed with `[browser]`).
10+
11+
## Example
12+
13+
For example, if you have the following code in your application:
14+
15+
```jsx title="src/App.jsx"
16+
const App = () => {
17+
const item = undefined;
18+
return <div>{item.name}</div>;
19+
};
20+
```
21+
22+
The browser will throw an error, and Rsbuild will forward this error to the terminal:
23+
24+
```bash
25+
error [browser] Uncaught TypeError: Cannot read properties of undefined (reading 'name') (src/App.jsx:3:0)
26+
```
27+
28+
## Disabling
29+
30+
Set `dev.browserLogs` to `false` to disable this behavior.
31+
32+
```ts title="rsbuild.config.ts"
33+
export default {
34+
dev: {
35+
browserLogs: false,
36+
},
37+
};
38+
```
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# dev.browserLogs
2+
3+
- **类型:** `boolean`
4+
- **默认值:** `true`
5+
- **版本:** 新增于 v1.5.13
6+
7+
控制是否将浏览器运行时错误转发到终端。
8+
9+
当设置为 `true` 时,Rsbuild 的客户端会监听浏览器中的 window `error` 事件,并将它们发送到开发服务器,然后在终端中打印(带有 `[browser]` 为前缀)。
10+
11+
## 示例
12+
13+
例如,如果你的应用中有以下代码:
14+
15+
```jsx title="src/App.jsx"
16+
const App = () => {
17+
const item = undefined;
18+
return <div>{item.name}</div>;
19+
};
20+
```
21+
22+
浏览器会抛出错误,Rsbuild 会将此错误转发到终端:
23+
24+
```bash
25+
error [browser] Uncaught TypeError: Cannot read properties of undefined (reading 'name') (src/App.jsx:3:0)
26+
```
27+
28+
## 禁用
29+
30+
`dev.browserLogs` 设置为 `false` 可以禁用此行为。
31+
32+
```ts title="rsbuild.config.ts"
33+
export default {
34+
dev: {
35+
browserLogs: false,
36+
},
37+
};
38+
```

0 commit comments

Comments
 (0)