undefined
Watch specified files and directories for changes. When a file change is detected, it can trigger a page reload or restart the dev server.
string | string[]
undefined
Paths of the files or directories to be watched, supports glob syntax. It can be a single path or an array of multiple paths.
'reload-page' | 'reload-server'
'reload-page'
Specifies whether to trigger a page reload or restart the dev server when a file changes.
reload-page
means that when a file changes, the page opened in the browser will automatically reload. If the type is not explicitly specified, Rsbuild will default to the reload-page
behavior.
This can be used to watch changes to static assets, such as files in the public
directory.
If both dev.hmr and dev.liveReload are set to
false
, the page will not automatically reload.
reload-server
means that the dev server will automatically restart when a file changes. This can be used to watch changes to configuration files, such as modules imported by the rsbuild.config.ts
file.
For example, if you maintain some common configuration files in the config
directory, such as common.ts
, you want the dev server to automatically restart when these files change. Example configuration:
It should be noted that the reload-server functionality is provided by Rsbuild CLI. If you are using a custom server or an upper-layer framework based on the Rsbuild, this configuration is currently not supported.
ChokidarOptions
undefined
watchFiles
is implemented based on chokidar v4, and you can pass chokidar options through options
.
watchFiles
is not applicable for watching build dependency files. When an Rsbuild build starts, the underlying Rspack will automatically watches all build dependencies. Any changes to these files will trigger a new build.
If you want to prevent some files from triggering a rebuild when they change, you can use Rspack's watchOptions.ignored configuration item.
For example, to prevent changes in the node_modules
directory from triggering a rebuild, you can add the following configuration: