close
logologo
Guide
Config
Plugin
API
Community
Version
Changelog
Rsbuild 0.x Doc
English
简体中文
Guide
Config
Plugin
API
Community
Changelog
Rsbuild 0.x Doc
English
简体中文
logologo

Getting Started

Introduction
Quick start
Features
Glossary

Framework

React
Vue
Preact
Svelte
Solid

Basic

CLI
Dev server
Output files
Static assets
HTML
JSON
Wasm
TypeScript
Web Workers
Deploy static site
Upgrade Rsbuild

Configuration

Configure Rspack
Configure Rsbuild
Configure SWC

Styling

CSS
CSS Modules
CSS-in-JS
Tailwind CSS v4
Tailwind CSS v3
UnoCSS

Advanced

Path aliases
Environment variables
Hot module replacement
Browserslist
Browser compatibility
Module Federation
Multi-environment builds
Server-side rendering (SSR)
Testing

Optimization

Code splitting
Bundle size optimization
Improve build performance
Inline static assets

Migration

Migrating from Rsbuild 0.x
webpack
Create React App
Vue CLI
Vite
Vite plugin
Modern.js Builder

Debug

Debug mode
Build profiling
Use Rsdoctor

FAQ

General FAQ
Features FAQ
Exceptions FAQ
HMR FAQ
📝 Edit this page on GitHub
Previous PageEnvironment variables
Next PageBrowserslist

#Hot module replacement

Hot Module Replacement (HMR) exchanges, adds, or removes modules while an application is running, without a full reload. This can significantly speed up development in a few ways:

  • Retain application state which is lost during a full reload.
  • Save valuable development time by only updating what's changed.
  • Instantly update the browser when modifications are made to CSS / JS in the source code, which is almost comparable to changing styles directly in the browser's dev tools.

#HMR toggle

Rsbuild has built-in support for HMR, which is enabled by default in development mode.

If you don't need HMR, set dev.hmr to false. This will disable HMR and react-refresh, and Rsbuild will automatically fall back to dev.liveReload.

rsbuild.config.ts
export default {
  dev: {
    hmr: false,
  },
};

To disable both HMR and liveReload, set both dev.hmr and dev.liveReload to false. Then, no WebSocket requests will be made to the dev server on the page, and the page will not automatically refresh when files change.

rsbuild.config.ts
export default {
  dev: {
    hmr: false,
    liveReload: false,
  },
};

#Specify HMR URL

By default, Rsbuild uses the host and port number of the current page to construct the WebSocket URL for HMR.

When the HMR connection fails, you can specify the WebSocket URL by customizing dev.client config.

rsbuild.config.ts
export default {
  dev: {
    client: {
      host: 'localhost',
      protocol: 'ws',
    },
  },
};

#File watching

By default, Rsbuild does not watch files in the .git/ and node_modules/ directories. When files in these directories change, Rsbuild will not trigger a rebuild. This reduces memory usage and improves build performance.

If you want to watch these directories, you can manually configure Rspack's watchOptions.ignored to override the default behavior.

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

rsbuild.config.ts
export default {
  tools: {
    rspack: {
      watchOptions: {
        ignored: /\.git/,
      },
    },
  },
};

#FAQ

Refer to HMR FAQ.