Skip to content

Commit

Permalink
docs: add guide for Preact (#2694)
Browse files Browse the repository at this point in the history
  • Loading branch information
fi3ework authored and chenjiahan committed Jun 25, 2024
1 parent 597ef40 commit 3dd85dc
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 2 deletions.
2 changes: 1 addition & 1 deletion website/docs/en/guide/framework/_meta.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
["react", "vue3", "vue2", "svelte", "solid"]
["react", "vue3", "vue2", "preact", "svelte", "solid"]
35 changes: 35 additions & 0 deletions website/docs/en/guide/framework/preact.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Preact

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

## Create Preact Project

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

import { PackageManagerTabs } from '@theme';

<PackageManagerTabs
command={{
npm: 'npm create rsbuild@latest',
yarn: 'yarn create rsbuild',
pnpm: 'pnpm create rsbuild@latest',
bun: 'bun 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](/plugins/list/plugin-preact). The plugin will automatically add the necessary configuration for Preact builds.

For example, register in `rsbuild.config.ts`:

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

export default defineConfig({
plugins: [pluginPreact()],
});
```
2 changes: 1 addition & 1 deletion website/docs/zh/guide/framework/_meta.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
["react", "vue3", "vue2", "svelte", "solid"]
["react", "vue3", "vue2", "preact", "svelte", "solid"]
35 changes: 35 additions & 0 deletions website/docs/zh/guide/framework/preact.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Preact

在这篇文档中,你可以了解到如何基于 Rsbuild 来构建一个 Preact 应用。

## 创建 Preact 项目

你可以使用 `create-rsbuild` 来创建一个 Rsbuild + Preact 的项目,调用以下命令:

import { PackageManagerTabs } from '@theme';

<PackageManagerTabs
command={{
npm: 'npm create rsbuild@latest',
yarn: 'yarn create rsbuild',
pnpm: 'pnpm create rsbuild@latest',
bun: 'bun create rsbuild@latest',
}}
/>

然后在 `Select framework` 时选择 `Preact` 即可。

## 在已有项目中使用 Preact

为了能够编译 Preact,你需要注册 Rsbuild 的 [Preact 插件](/plugins/list/plugin-preact),插件会自动添加 Preact 构建所需的配置。

例如,在 `rsbuild.config.ts` 中注册:

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

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

0 comments on commit 3dd85dc

Please sign in to comment.