This document explains how to use Rsbuild to build a React application.
Create a React application with Rsbuild using create-rsbuild. Run this command:
Then select React 19 or React 18 when prompted to "Select framework".
To compile React's JSX syntax, you need to register the Rsbuild React Plugin. The plugin automatically adds the necessary configuration for building React applications.
For example, register in rsbuild.config.ts:
For projects using Create React App, you can refer to the CRA Migration Guide.
Rsbuild supports converting SVG to React components via SVGR.
To use SVGR, you also need to register the SVGR plugin.
Rsbuild uses React's official Fast Refresh capability to perform component hot updates.
Note that React Refresh requires components to follow certain standards, otherwise HMR may not work. You can use eslint-plugin-react-refresh to validate your code.
For example, if React component hot updates don't work, or component state is lost after hot updates, it's usually because your React component uses an anonymous function. React Fast Refresh requires that components have named functions, otherwise component state cannot be preserved after hot updates.
Here are some examples of wrong usage:
The correct usage is to declare a name for each component function:
React Compiler is a build-time tool that automatically optimizes your React app. It works with plain JavaScript, and understands the Rules of React, so you don’t need to rewrite any code to use it.
Before using React Compiler, we recommend reading the React Compiler documentation to understand its functionality, current state, and usage.
Steps to use React Compiler in Rsbuild:
react and react-dom to v19. If you can't upgrade, you can install the react-compiler-runtime package, which allows the compiled code to run on versions prior to 19.You can also refer to the example project.
Set the config for React Compiler as follows:
For React 17 and 18 projects, you need to install react-compiler-runtime and specify the target:
TanStack Router is a fully type-safe React router with built-in data fetching, stale-while revalidate caching and first-class search-param APIs.
TanStack Router provides @tanstack/router-plugin to integrate with Rsbuild, which provides support for file-based routing. See:
React Router is a user‑obsessed, standards‑focused, multi‑strategy router for React.
See CSS-in-JS for how to use CSS-in-JS in Rsbuild.
Rsbuild uses SWC to compile JSX. You can customize the functions used by the compiled JSX code:
automatic, use jsxImportSource to customize the import path of the JSX runtime, for example, import from Preact or Emotion.classic, use pragma and pragmaFrag to specify the JSX function and Fragment component.
@rsbuild/plugin-reactusesautomaticas the default JSX runtime, see swcReactOptions.runtime.
Configure through the @rsbuild/plugin-react's swcReactOptions.
runtime is automatic:runtime is classic:You can also customize JSX behavior by adding specific comments at the top of individual JSX or TSX files, which will take precedence over the configuration.
automatic:classic:React Scan can automatically detect performance issues in your React app.
See React Scan - Rsbuild Guide to learn how to use React Scan with Rsbuild.