diff --git a/packages/core/src/types/config.ts b/packages/core/src/types/config.ts index 1a13ee0425..37cc1fc9f2 100644 --- a/packages/core/src/types/config.ts +++ b/packages/core/src/types/config.ts @@ -1720,7 +1720,7 @@ export type WriteToDisk = boolean | ((filename: string) => boolean); export interface DevConfig { /** - * Enables forwarding of browser runtime errors to the terminal. When `true`, the dev + * Controls whether to forward browser runtime errors to the terminal. When `true`, the dev * 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]`). * @default true diff --git a/website/docs/en/config/dev/browser-logs.mdx b/website/docs/en/config/dev/browser-logs.mdx new file mode 100644 index 0000000000..82c64aec29 --- /dev/null +++ b/website/docs/en/config/dev/browser-logs.mdx @@ -0,0 +1,38 @@ +# dev.browserLogs + +- **Type:** `boolean` +- **Default:** `true` +- **Version:** Added in v1.5.13 + +Controls whether to forward browser runtime errors to the terminal. + +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]`). + +## Example + +For example, if you have the following code in your application: + +```jsx title="src/App.jsx" +const App = () => { + const item = undefined; + return
{item.name}
; +}; +``` + +The browser will throw an error, and Rsbuild will forward this error to the terminal: + +```bash +error [browser] Uncaught TypeError: Cannot read properties of undefined (reading 'name') (src/App.jsx:3:0) +``` + +## Disabling + +Set `dev.browserLogs` to `false` to disable this behavior. + +```ts title="rsbuild.config.ts" +export default { + dev: { + browserLogs: false, + }, +}; +``` diff --git a/website/docs/zh/config/dev/browser-logs.mdx b/website/docs/zh/config/dev/browser-logs.mdx new file mode 100644 index 0000000000..bb55b5dd5d --- /dev/null +++ b/website/docs/zh/config/dev/browser-logs.mdx @@ -0,0 +1,38 @@ +# dev.browserLogs + +- **类型:** `boolean` +- **默认值:** `true` +- **版本:** 新增于 v1.5.13 + +控制是否将浏览器运行时错误转发到终端。 + +当设置为 `true` 时,Rsbuild 的客户端会监听浏览器中的 window `error` 事件,并将它们发送到开发服务器,然后在终端中打印(带有 `[browser]` 为前缀)。 + +## 示例 + +例如,如果你的应用中有以下代码: + +```jsx title="src/App.jsx" +const App = () => { + const item = undefined; + return
{item.name}
; +}; +``` + +浏览器会抛出错误,Rsbuild 会将此错误转发到终端: + +```bash +error [browser] Uncaught TypeError: Cannot read properties of undefined (reading 'name') (src/App.jsx:3:0) +``` + +## 禁用 + +将 `dev.browserLogs` 设置为 `false` 可以禁用此行为。 + +```ts title="rsbuild.config.ts" +export default { + dev: { + browserLogs: false, + }, +}; +```