Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: update file watching #4061

Merged
merged 1 commit into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 1 addition & 13 deletions website/docs/en/config/dev/watch-files.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -134,16 +134,4 @@ export default {

If you want to prevent some files from triggering a rebuild when they change, you can use Rspack's [watchOptions.ignored](https://rspack.dev/config/watch#watchoptionsignored) configuration item.

For example, to prevent changes in the `node_modules` directory from triggering a rebuild, you can add the following configuration:

```js
export default {
tools: {
rspack: {
watchOptions: {
ignored: /node_modules/,
},
},
},
};
```
> See [HMR - File Watching](/guide/advanced/hmr#file-watching) for more details.
20 changes: 20 additions & 0 deletions website/docs/en/guide/advanced/hmr.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,26 @@ export default {
};
```

## File Watching

By default, Rsbuild does not watching files in the `.git/` and `node_modules/` directories. When files in these directories changed, Rsbuild will not trigger a rebuild. This helps to reduce memory usage and improve build performance.

If you want to watch these directories, you can manually configure Rspack's [watchOptions.ignored](https://rspack.dev/config/watch#watchoptionsignored) to override the default behavior.

For example, to watch the `node_modules/` directory and ignore the `.git/` directory, you can configure it as follows:

```js title="rsbuild.config.ts"
export default {
tools: {
rspack: {
watchOptions: {
ignored: /\.git/,
},
},
},
};
```

## FAQ

Please refer to [HMR FAQ](/guide/faq/hmr).
14 changes: 1 addition & 13 deletions website/docs/zh/config/dev/watch-files.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -155,16 +155,4 @@ export default {

如果你希望当某些文件变化时,不触发重新构建,可以使用 Rspack 的 [watchOptions.ignored](https://rspack.dev/config/watch#watchoptionsignored) 配置项。

例如,指定当 `node_modules` 中文件发生变化时,不触发重新构建,可以添加如下配置:

```js
export default {
tools: {
rspack: {
watchOptions: {
ignored: /node_modules/,
},
},
},
};
```
> 详见 [模块热更新 - 文件监听](/guide/advanced/hmr#文件监听)。
20 changes: 20 additions & 0 deletions website/docs/zh/guide/advanced/hmr.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,26 @@ export default {
};
```

## 文件监听

Rsbuild 默认不监听 `.git/` 和 `node_modules/` 目录下的文件,当这些目录下的文件发生变化时,Rsbuild 不会触发重新构建。这有助于减少内存占用和提升构建性能。

如果你希望监听这些目录,可以手动配置 Rspack 的 [watchOptions.ignored](https://rspack.dev/config/watch#watchoptionsignored) 来覆盖默认行为。

例如,监听 `node_modules/` 目录且忽略 `.git/` 目录,可以配置为:

```js title="rsbuild.config.ts"
export default {
tools: {
rspack: {
watchOptions: {
ignored: /\.git/,
},
},
},
};
```

## 常见问题

请参考 [热更新问题](/guide/faq/hmr)。
Loading