@vitejs/plugin-react 5.0.3 → 5.0.4
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 +0 -4
- package/dist/index.js +46 -4
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -127,10 +127,6 @@ Otherwise, you'll probably get this error:
|
|
|
127
127
|
Uncaught Error: @vitejs/plugin-react can't detect preamble. Something is wrong.
|
|
128
128
|
```
|
|
129
129
|
|
|
130
|
-
### disableOxcRecommendation
|
|
131
|
-
|
|
132
|
-
If set, disables the recommendation to use `@vitejs/plugin-react-oxc` (which is shown when `rolldown-vite` is detected and `babel` is not configured).
|
|
133
|
-
|
|
134
130
|
## Consistent components exports
|
|
135
131
|
|
|
136
132
|
For React refresh to work correctly, your file should only export React components. You can find a good explanation in the [Gatsby docs](https://www.gatsbyjs.com/docs/reference/local-development/fast-refresh/#how-it-works).
|
package/dist/index.js
CHANGED
|
@@ -80,6 +80,8 @@ function viteReact(opts = {}) {
|
|
|
80
80
|
let isProduction = true;
|
|
81
81
|
let projectRoot = process.cwd();
|
|
82
82
|
let skipFastRefresh = true;
|
|
83
|
+
let base;
|
|
84
|
+
let isFullBundle = false;
|
|
83
85
|
let runPluginOverrides;
|
|
84
86
|
let staticBabelOptions;
|
|
85
87
|
const importReactRE = /\bimport\s+(?:\*\s+as\s+)?React\b/;
|
|
@@ -119,6 +121,8 @@ function viteReact(opts = {}) {
|
|
|
119
121
|
},
|
|
120
122
|
configResolved(config) {
|
|
121
123
|
runningInVite = true;
|
|
124
|
+
base = config.base;
|
|
125
|
+
if (config.experimental.fullBundleMode) isFullBundle = true;
|
|
122
126
|
projectRoot = config.root;
|
|
123
127
|
isProduction = config.isProduction;
|
|
124
128
|
skipFastRefresh = isProduction || config.command === "build" || config.server.hmr === false;
|
|
@@ -214,6 +218,26 @@ function viteReact(opts = {}) {
|
|
|
214
218
|
const viteRefreshWrapper = {
|
|
215
219
|
name: "vite:react:refresh-wrapper",
|
|
216
220
|
apply: "serve",
|
|
221
|
+
async applyToEnvironment(env) {
|
|
222
|
+
if (env.config.consumer !== "client" || skipFastRefresh) return false;
|
|
223
|
+
let nativePlugin;
|
|
224
|
+
try {
|
|
225
|
+
nativePlugin = (await import("vite/internal")).reactRefreshWrapperPlugin;
|
|
226
|
+
} catch {}
|
|
227
|
+
if (!nativePlugin || [
|
|
228
|
+
"7.1.10",
|
|
229
|
+
"7.1.11",
|
|
230
|
+
"7.1.12"
|
|
231
|
+
].includes(vite.version)) return true;
|
|
232
|
+
delete viteRefreshWrapper.transform;
|
|
233
|
+
return nativePlugin({
|
|
234
|
+
cwd: process.cwd(),
|
|
235
|
+
include: makeIdFiltersToMatchWithQuery(include),
|
|
236
|
+
exclude: makeIdFiltersToMatchWithQuery(exclude),
|
|
237
|
+
jsxImportSource,
|
|
238
|
+
reactRefreshHost: opts.reactRefreshHost ?? ""
|
|
239
|
+
});
|
|
240
|
+
},
|
|
217
241
|
transform: {
|
|
218
242
|
filter: { id: {
|
|
219
243
|
include: makeIdFiltersToMatchWithQuery(include),
|
|
@@ -239,6 +263,20 @@ function viteReact(opts = {}) {
|
|
|
239
263
|
if (userConfig.server?.hmr === false) return { oxc: { jsx: { refresh: false } } };
|
|
240
264
|
}
|
|
241
265
|
};
|
|
266
|
+
const viteReactRefreshFullBundleMode = {
|
|
267
|
+
name: "vite:react-refresh-fbm",
|
|
268
|
+
enforce: "pre",
|
|
269
|
+
transformIndexHtml: {
|
|
270
|
+
handler() {
|
|
271
|
+
if (!skipFastRefresh && isFullBundle) return [{
|
|
272
|
+
tag: "script",
|
|
273
|
+
attrs: { type: "module" },
|
|
274
|
+
children: getPreambleCode(base)
|
|
275
|
+
}];
|
|
276
|
+
},
|
|
277
|
+
order: "pre"
|
|
278
|
+
}
|
|
279
|
+
};
|
|
242
280
|
const dependencies = [
|
|
243
281
|
"react",
|
|
244
282
|
"react-dom",
|
|
@@ -270,17 +308,21 @@ function viteReact(opts = {}) {
|
|
|
270
308
|
if (id === runtimePublicPath) return readFileSync(refreshRuntimePath, "utf-8").replace(/__README_URL__/g, "https://github.com/vitejs/vite-plugin-react/tree/main/packages/plugin-react");
|
|
271
309
|
}
|
|
272
310
|
},
|
|
273
|
-
transformIndexHtml(
|
|
274
|
-
if (!skipFastRefresh) return [{
|
|
311
|
+
transformIndexHtml() {
|
|
312
|
+
if (!skipFastRefresh && !isFullBundle) return [{
|
|
275
313
|
tag: "script",
|
|
276
314
|
attrs: { type: "module" },
|
|
277
|
-
children: getPreambleCode(
|
|
315
|
+
children: getPreambleCode(base)
|
|
278
316
|
}];
|
|
279
317
|
}
|
|
280
318
|
};
|
|
281
319
|
return [
|
|
282
320
|
viteBabel,
|
|
283
|
-
...isRolldownVite ? [
|
|
321
|
+
...isRolldownVite ? [
|
|
322
|
+
viteRefreshWrapper,
|
|
323
|
+
viteConfigPost,
|
|
324
|
+
viteReactRefreshFullBundleMode
|
|
325
|
+
] : [],
|
|
284
326
|
viteReactRefresh
|
|
285
327
|
];
|
|
286
328
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vitejs/plugin-react",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.4",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Evan You",
|
|
6
6
|
"description": "The default Vite plugin for React projects",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"@babel/core": "^7.28.4",
|
|
44
44
|
"@babel/plugin-transform-react-jsx-self": "^7.27.1",
|
|
45
45
|
"@babel/plugin-transform-react-jsx-source": "^7.27.1",
|
|
46
|
-
"@rolldown/pluginutils": "1.0.0-beta.
|
|
46
|
+
"@rolldown/pluginutils": "1.0.0-beta.38",
|
|
47
47
|
"@types/babel__core": "^7.20.5",
|
|
48
48
|
"react-refresh": "^0.17.0"
|
|
49
49
|
},
|
|
@@ -55,8 +55,8 @@
|
|
|
55
55
|
"babel-plugin-react-compiler": "19.1.0-rc.3",
|
|
56
56
|
"react": "^19.1.1",
|
|
57
57
|
"react-dom": "^19.1.1",
|
|
58
|
-
"rolldown": "1.0.0-beta.
|
|
59
|
-
"tsdown": "^0.
|
|
58
|
+
"rolldown": "1.0.0-beta.38",
|
|
59
|
+
"tsdown": "^0.15.4",
|
|
60
60
|
"vitest": "^3.2.4"
|
|
61
61
|
}
|
|
62
62
|
}
|