Skip to content

Commit 816d800

Browse files
hi-ogawaclaudebluwy
authored
docs: add RSC support (vitejs#20618)
Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: Bjorn Lu <bjornlu.dev@gmail.com>
1 parent e899bc7 commit 816d800

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed

docs/guide/api-environment-plugins.md

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,19 @@ A plugin could use the `environment` instance to change how a module is processe
3131

3232
## Registering New Environments Using Hooks
3333

34-
Plugins can add new environments in the `config` hook (for example to have a separate module graph for [RSC](https://react.dev/blog/2023/03/22/react-labs-what-we-have-been-working-on-march-2023#react-server-components)):
34+
Plugins can add new environments in the `config` hook. For example, [RSC support](/plugins/#vitejs-plugin-rsc) uses an additional environment to have a separate module graph with the `react-server` condition:
3535

3636
```ts
3737
config(config: UserConfig) {
38-
config.environments.rsc ??= {}
38+
return {
39+
environments: {
40+
rsc: {
41+
resolve: {
42+
conditions: ['react-server', ...defaultServerConditions],
43+
},
44+
},
45+
},
46+
}
3947
}
4048
```
4149

@@ -48,8 +56,15 @@ Plugins should set default values using the `config` hook. To configure each env
4856

4957
```ts
5058
configEnvironment(name: string, options: EnvironmentOptions) {
59+
// add "workerd" condition to the rsc environment
5160
if (name === 'rsc') {
52-
options.resolve.conditions = // ...
61+
return {
62+
resolve: {
63+
conditions: ['workerd'],
64+
},
65+
}
66+
}
67+
}
5368
```
5469

5570
## The `hotUpdate` Hook

docs/guide/features.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ All modern frameworks maintain integrations with Vite. Most framework plugins ar
213213
- Vue JSX support via [@vitejs/plugin-vue-jsx](https://github.com/vitejs/vite-plugin-vue/tree/main/packages/plugin-vue-jsx)
214214
- React support via [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/tree/main/packages/plugin-react)
215215
- React using SWC support via [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react/tree/main/packages/plugin-react-swc)
216+
- [React Server Components (RSC)](https://react.dev/reference/rsc/server-components) support via [@vitejs/plugin-rsc](https://github.com/vitejs/vite-plugin-react/tree/main/packages/plugin-rsc)
216217

217218
Check out the [Plugins Guide](/plugins/) for more information.
218219

docs/plugins/index.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,16 @@ Uses esbuild and Babel, achieving fast HMR with a small package footprint and th
2424

2525
Replaces Babel with SWC during development. During production builds, SWC+esbuild are used when using plugins, and esbuild only otherwise. For big projects that don't require non-standard React extensions, cold start and Hot Module Replacement (HMR) can be significantly faster.
2626

27+
### [@vitejs/plugin-rsc](https://github.com/vitejs/vite-plugin-react/tree/main/packages/plugin-rsc)
28+
29+
Vite supports [React Server Components (RSC)](https://react.dev/reference/rsc/server-components) through the plugin. It utilizes the [Environment API](/guide/api-environment) to provide low-level primitives that React frameworks can use to integrate RSC features. You can try a minimal standalone RSC application with:
30+
31+
```bash
32+
npm create vite@latest -- --template rsc
33+
```
34+
35+
Read the [plugin documentation](https://github.com/vitejs/vite-plugin-react/tree/main/packages/plugin-rsc) to learn more.
36+
2737
### [@vitejs/plugin-legacy](https://github.com/vitejs/vite/tree/main/packages/plugin-legacy)
2838

2939
Provides legacy browsers support for the production build.

0 commit comments

Comments
 (0)