Skip to content

Commit a0329a0

Browse files
authored
docs(react): clarify react compiler preset filter (#1137)
1 parent 704e0d3 commit a0329a0

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

packages/plugin-react/README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,19 @@ babel({
107107
})
108108
```
109109

110+
> [!TIP]
111+
>
112+
> `reactCompilerPreset` is only a convenient helper with a preconfigured filter. You can configure override the filters to fit your project structure or code. For example, if you know a large portion of your files are never React/hook-related or won't benefit from the React Compiler, you can aggressively exclude them via `rolldown.filter`:
113+
>
114+
> ```js
115+
> const myPreset = reactCompilerPreset()
116+
> myPreset.rolldown.filter.id.exclude = ['src/legacy/**', 'src/utils/**']
117+
>
118+
> babel({
119+
> presets: [myPreset],
120+
> })
121+
> ```
122+
110123
## `@vitejs/plugin-react/preamble`
111124
112125
The package provides `@vitejs/plugin-react/preamble` to initialize HMR runtime from client entrypoint for SSR applications which don't use [`transformIndexHtml` API](https://vite.dev/guide/api-javascript.html#vitedevserver). For example:

packages/plugin-react/src/reactCompilerPreset.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export const reactCompilerPreset = (
1414
}),
1515
rolldown: {
1616
filter: {
17+
// should be lax than https://github.com/facebook/react/blob/9c0323e2cf9be543d6eaa44419598af56922603f/compiler/packages/babel-plugin-react-compiler/src/Entrypoint/Program.ts#L842-L863
1718
code:
1819
options.compilationMode === 'annotation'
1920
? /['"]use memo['"]/

0 commit comments

Comments
 (0)