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 PageVue
Next PageSvelte

#Preact

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

#Create a Preact application

Use create-rsbuild to create a Preact application with Rsbuild. Run the following command:

npm
yarn
pnpm
bun
npm create rsbuild@latest

Then select Preact when prompted to "Select framework".

#Use Preact in an existing project

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

For example, register in rsbuild.config.ts:

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

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

#Preact Fast Refresh

Preact plugin uses @preact/prefresh and @rspack/plugin-preact-refresh to hot reload Preact components.

#Component recognition

Prefresh needs to be able to recognize your components. This means that components should start with a capital letter and hooks should start with use followed by a capital letter. This allows the plugin to effectively recognize these.

Do note that a component as seen below is not named:

export default () => {
  return <p>Want to refresh</p>;
};

Instead do:

const MyComponent = () => {
  return <p>Want to refresh</p>;
};

export default MyComponent;

When you are working with HOC's be sure to lift up the displayName so the plugin can recognize it as a component.