In this document, you will learn how to build a Preact application using Rsbuild.
You can use create-rsbuild
to create a project with Rsbuild + Preact. Just execute the following command:
Then select Preact
when prompted to "Select framework".
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
:
Preact plugin uses @preact/prefresh and @rspack/plugin-preact-refresh to hot reload Preact components.
Prefresh need to be able to recognize your components, this means that components should
start with a capital letter and hook 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:
Instead do:
When you are working with HOC's be sure to lift up the displayName
so the plugin can
recognize it as a component.