@vitejs/plugin-react 6.0.0-beta.0 → 6.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -1
- package/dist/index.js +3 -8
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -107,6 +107,19 @@ babel({
|
|
|
107
107
|
})
|
|
108
108
|
```
|
|
109
109
|
|
|
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
|
+
|
|
110
123
|
## `@vitejs/plugin-react/preamble`
|
|
111
124
|
|
|
112
125
|
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:
|
|
@@ -145,4 +158,4 @@ For React refresh to work correctly, your file should only export React componen
|
|
|
145
158
|
|
|
146
159
|
If an incompatible change in exports is found, the module will be invalidated and HMR will propagate. To make it easier to export simple constants alongside your component, the module is only invalidated when their value changes.
|
|
147
160
|
|
|
148
|
-
You can catch mistakes and get more detailed
|
|
161
|
+
You can catch mistakes and get more detailed warnings with this [ESLint rule](https://github.com/ArnaudBarre/eslint-plugin-react-refresh), or the equivalent [Oxlint rule](https://oxc.rs/docs/guide/usage/linter/rules/react/only-export-components.html).
|
package/dist/index.js
CHANGED
|
@@ -3,7 +3,6 @@ import { dirname, join } from "node:path";
|
|
|
3
3
|
import { fileURLToPath } from "node:url";
|
|
4
4
|
import { exactRegex, makeIdFiltersToMatchWithQuery } from "@rolldown/pluginutils";
|
|
5
5
|
import { reactRefreshWrapperPlugin } from "vite/internal";
|
|
6
|
-
|
|
7
6
|
//#region ../common/refresh-utils.ts
|
|
8
7
|
const runtimePublicPath = "/@react-refresh";
|
|
9
8
|
const preambleCode = `import { injectIntoGlobalHook } from "__BASE__${runtimePublicPath.slice(1)}";
|
|
@@ -32,7 +31,6 @@ function virtualPreamblePlugin({ name, isEnabled }) {
|
|
|
32
31
|
}
|
|
33
32
|
};
|
|
34
33
|
}
|
|
35
|
-
|
|
36
34
|
//#endregion
|
|
37
35
|
//#region ../common/warning.ts
|
|
38
36
|
const silenceUseClientWarning = (userConfig) => ({ rollupOptions: { onwarn(warning, defaultHandler) {
|
|
@@ -41,7 +39,6 @@ const silenceUseClientWarning = (userConfig) => ({ rollupOptions: { onwarn(warni
|
|
|
41
39
|
if (userConfig.build?.rollupOptions?.onwarn) userConfig.build.rollupOptions.onwarn(warning, defaultHandler);
|
|
42
40
|
else defaultHandler(warning);
|
|
43
41
|
} } });
|
|
44
|
-
|
|
45
42
|
//#endregion
|
|
46
43
|
//#region src/reactCompilerPreset.ts
|
|
47
44
|
const reactCompilerPreset = (options = {}) => ({
|
|
@@ -52,7 +49,6 @@ const reactCompilerPreset = (options = {}) => ({
|
|
|
52
49
|
optimizeDeps: { include: options.target === "17" || options.target === "18" ? ["react-compiler-runtime"] : ["react/compiler-runtime"] }
|
|
53
50
|
}
|
|
54
51
|
});
|
|
55
|
-
|
|
56
52
|
//#endregion
|
|
57
53
|
//#region src/index.ts
|
|
58
54
|
const refreshRuntimePath = join(dirname(fileURLToPath(import.meta.url)), "refresh-runtime.js");
|
|
@@ -168,13 +164,13 @@ function viteReact(opts = {}) {
|
|
|
168
164
|
resolveId: {
|
|
169
165
|
filter: { id: exactRegex(runtimePublicPath) },
|
|
170
166
|
handler(id) {
|
|
171
|
-
if (id ===
|
|
167
|
+
if (id === "/@react-refresh") return id;
|
|
172
168
|
}
|
|
173
169
|
},
|
|
174
170
|
load: {
|
|
175
171
|
filter: { id: exactRegex(runtimePublicPath) },
|
|
176
172
|
handler(id) {
|
|
177
|
-
if (id ===
|
|
173
|
+
if (id === "/@react-refresh") return readFileSync(refreshRuntimePath, "utf-8").replace(/__README_URL__/g, "https://github.com/vitejs/vite-plugin-react/tree/main/packages/plugin-react");
|
|
178
174
|
}
|
|
179
175
|
},
|
|
180
176
|
transformIndexHtml() {
|
|
@@ -199,6 +195,5 @@ Object.assign(viteReactForCjs, {
|
|
|
199
195
|
default: viteReactForCjs,
|
|
200
196
|
reactCompilerPreset
|
|
201
197
|
});
|
|
202
|
-
|
|
203
198
|
//#endregion
|
|
204
|
-
export { viteReact as default, viteReactForCjs as "module.exports", reactCompilerPreset };
|
|
199
|
+
export { viteReact as default, viteReactForCjs as "module.exports", reactCompilerPreset };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vitejs/plugin-react",
|
|
3
|
-
"version": "6.0.0
|
|
3
|
+
"version": "6.0.0",
|
|
4
4
|
"description": "The default Vite plugin for React projects",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"fast refresh",
|
|
@@ -43,17 +43,17 @@
|
|
|
43
43
|
"test-unit": "vitest run"
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@rolldown/pluginutils": "1.0.0-rc.
|
|
46
|
+
"@rolldown/pluginutils": "1.0.0-rc.7"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
49
|
"@babel/core": "8.0.0-rc.2",
|
|
50
|
-
"@rolldown/plugin-babel": "^0.
|
|
50
|
+
"@rolldown/plugin-babel": "^0.2.0",
|
|
51
51
|
"@vitejs/react-common": "workspace:*",
|
|
52
52
|
"babel-plugin-react-compiler": "^1.0.0",
|
|
53
53
|
"react": "^19.2.4",
|
|
54
54
|
"react-dom": "^19.2.4",
|
|
55
|
-
"rolldown": "1.0.0-rc.
|
|
56
|
-
"tsdown": "^0.
|
|
55
|
+
"rolldown": "1.0.0-rc.7",
|
|
56
|
+
"tsdown": "^0.21.0",
|
|
57
57
|
"vite": "^8.0.0-beta.16"
|
|
58
58
|
},
|
|
59
59
|
"peerDependencies": {
|