Skip to content

Commit 907b9d8

Browse files
hi-ogawaclaude
andauthored
docs(rsc): how to use @vitejs/plugin-rsc as framework's dependencies (#796)
Co-authored-by: Claude <[email protected]>
1 parent d8cfdfa commit 907b9d8

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

packages/plugin-rsc/README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,37 @@ export function Page() {
477477

478478
See https://github.com/vitejs/vite-plugin-react/pull/524 for how to install the package for React [canary](https://react.dev/community/versioning-policy#canary-channel) and [experimental](https://react.dev/community/versioning-policy#all-release-channels) usages.
479479

480+
## Using `@vitejs/plugin-rsc` as a framework package's `dependencies`
481+
482+
By default, `@vitejs/plugin-rsc` is expected to be used as `peerDependencies` similar to `react` and `react-dom`. When `@vitejs/plugin-rsc` is not available at the project root (e.g., in `node_modules/@vitejs/plugin-rsc`), you will see warnings like:
483+
484+
```sh
485+
Failed to resolve dependency: @vitejs/plugin-rsc/vendor/react-server-dom/client.browser, present in client 'optimizeDeps.include'
486+
```
487+
488+
This can be fixed by updating `optimizeDeps.include` to reference `@vitejs/plugin-rsc` through your framework package. For example, you can add the following plugin:
489+
490+
```js
491+
// package name is "my-rsc-framework"
492+
export default function myRscFrameworkPlugin() {
493+
return {
494+
name: 'my-rsc-framework:config',
495+
configEnvironment(_name, config) {
496+
if (config.optimizeDeps?.include) {
497+
config.optimizeDeps.include = config.optimizeDeps.include.map(
498+
(entry) => {
499+
if (entry.startsWith('@vitejs/plugin-rsc')) {
500+
entry = `my-rsc-framework > ${entry}`
501+
}
502+
return entry
503+
},
504+
)
505+
}
506+
},
507+
}
508+
}
509+
```
510+
480511
## Credits
481512
482513
This project builds on fundamental techniques and insights from pioneering Vite RSC implementations.

0 commit comments

Comments
 (0)