close

Preact plugin

The Preact plugin provides support for Preact, integrating features such as JSX compilation and React aliasing.

Quick start

Install plugin

Run the following command:

npm
yarn
pnpm
bun
deno
npm add @rsbuild/plugin-preact -D

Register plugin

Register the plugin in Rsbuild config:

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

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

After registration, you can develop Preact directly.

Options

reactAliasesEnabled

Whether to aliases react, react-dom to preact/compat.

  • Type: boolean
  • Default: true
  • Example: Disable aliases.
pluginPreact({
  reactAliasesEnabled: false,
});

prefreshEnabled

Whether to inject Prefresh for HMR.

  • Type: boolean
  • Default: true
  • Version: >= v1.1.0
  • Example: Disable Prefresh.
pluginPreact({
  prefreshEnabled: false,
});

include

Include files to be processed by the @rspack/plugin-preact-refresh plugin. The value is the same as the rules[].test option in Rspack.

pluginPreact({
  include: [/\.(?:js|jsx|mjs|cjs|ts|tsx|mts|cts)$/, /some-other-module/],
});

exclude

Exclude files from being processed by the @rspack/plugin-preact-refresh plugin. The value is the same as the rules[].exclude option in Rspack.

pluginPreact({
  exclude: [/[\\/]node_modules[\\/]/, /some-other-module/],
});