dev.watchFiles
- Type:
- Default:
undefined
Watch specified files and directories for changes. When a change is detected, it can trigger a page reload or restart the dev server or watch build.
paths
- Type:
string | string[] - Default:
undefined
Paths of the files or directories to watch, supports glob syntax. It can be a single path or an array of multiple paths.
- Watching a single file:
- Using glob to match multiple files:
- Watching multiple file paths:
Glob patterns are expanded when the watcher starts and do not include new matching paths created later. To observe files that may be added after startup, watch their parent directory instead.
Glob patterns should use forward slashes (/) as path separators on all platforms. Avoid using path.join() to construct glob patterns because it produces backslashes on Windows, where backslashes are interpreted as escape characters in glob syntax.
Use a string literal or path.posix.join() to construct relative glob patterns.
events
- Type:
('add' | 'change' | 'unlink')[] - Default:
['add', 'change', 'unlink']
Specifies the file events that trigger the configured action:
add: A watched file is detected. By default, only files that appear after the watcher starts trigger this event. Ifoptions.ignoreInitialisfalse, existing files also trigger it during startup.change: A watched file changes.unlink: A watched file disappears.
For example, to restart only when files are added to or removed from a directory:
type
- Type:
'reload-page' | 'restart' | 'reload-server' - Default:
'reload-page'
Specifies whether to trigger a page reload or restart the dev server or watch build when a file changes.
reload-page
reload-page means that when a watched file event specified by events occurs, the page in the browser automatically reloads. By default, additions, changes, and removals all trigger a reload. If type is not explicitly specified, Rsbuild uses reload-page.
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.
restart
restart requests a dev server restart when running rsbuild dev, or a watch build restart when running rsbuild build --watch.
This can be used to watch configuration files whose changes require Rsbuild to be reinitialized.
For example, if you maintain some common configuration files in the config directory, such as common.ts, you may want changes to these files to restart the dev server or watch build:
For details about automatic config file watching and restart behavior, see Configuration file watching.
reload-server
reload-server is a deprecated alias for restart. It remains supported for backward compatibility.
options
- Type:
ChokidarOptions - Default:
undefined
watchFiles is implemented based on chokidar v4, and you can pass chokidar options through options.
Notes
watchFiles is not applicable for watching build dependency files. When an Rsbuild build starts, the underlying Rspack 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.
See HMR - File Watching for details.

