React

In this document, you will learn how to build a React application using Rsbuild.

Create React Project

You can use create-rsbuild to create a project with Rsbuild + React. Just execute the following command:

npm
yarn
pnpm
bun
npm create rsbuild@latest

Then select React when prompted to "Select framework".

Use React in an existing project

To compile React, you need to register the Rsbuild React Plugin. The plugin will automatically add the necessary configuration for React builds.

For example, register in rsbuild.config.ts:

rsbuild.config.ts
import { defineConfig } from '@rsbuild/core';
import { pluginReact } from '@rsbuild/plugin-react';

export default defineConfig({
  plugins: [pluginReact()],
});

Use SVGR

Rsbuild supports convert SVG to React components via SVGR.

If you need to use svgr, you also need to register the SVGR plugin.

Use styled-components

Rsbuild provides compile-time support for styled-components, improve the debugging experience and add server-side rendering support to styled-components.

If you need to use styled-components, We recommend register the Styled Components plugin.

Deploy the Application

After executing rsbuild build to build the application, you will get a set of static assets in the dist directory. These assets can be deployed to any platform or server.

Please note that the default output structure of Rsbuild may not be suitable for all platforms because different platforms have different requirements for the directory structure. You can refer to the Output Files section to modify the directory structure to meet the requirements of your deployment platform.

Additionally, if you need to preview the deployment artifacts locally, you can use the rsbuild preview command provided by Rsbuild CLI.