@vitejs/plugin-react 5.0.0 → 5.0.1
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 +1 -1
- package/dist/index.js +20 -11
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -38,7 +38,7 @@ export default defineConfig({
|
|
|
38
38
|
|
|
39
39
|
### jsxImportSource
|
|
40
40
|
|
|
41
|
-
Control where the JSX factory is imported from.
|
|
41
|
+
Control where the JSX factory is imported from. By default, this is inferred from `jsxImportSource` from corresponding a tsconfig file for a transformed file.
|
|
42
42
|
|
|
43
43
|
```js
|
|
44
44
|
react({ jsxImportSource: '@emotion/react' })
|
package/dist/index.js
CHANGED
|
@@ -101,6 +101,7 @@ async function loadBabel() {
|
|
|
101
101
|
const defaultIncludeRE = /\.[tj]sx?$/;
|
|
102
102
|
const defaultExcludeRE = /\/node_modules\//;
|
|
103
103
|
const tsRE = /\.tsx?$/;
|
|
104
|
+
const compilerAnnotationRE = /['"]use memo['"]/;
|
|
104
105
|
function viteReact(opts = {}) {
|
|
105
106
|
const include = opts.include ?? defaultIncludeRE;
|
|
106
107
|
const exclude = opts.exclude ?? defaultExcludeRE;
|
|
@@ -133,19 +134,19 @@ function viteReact(opts = {}) {
|
|
|
133
134
|
oxc: {
|
|
134
135
|
jsx: {
|
|
135
136
|
runtime: "automatic",
|
|
136
|
-
importSource: jsxImportSource,
|
|
137
|
+
importSource: opts.jsxImportSource,
|
|
137
138
|
refresh: command === "serve"
|
|
138
139
|
},
|
|
139
140
|
jsxRefreshInclude: include,
|
|
140
141
|
jsxRefreshExclude: exclude
|
|
141
142
|
},
|
|
142
|
-
optimizeDeps: { rollupOptions: { jsx: {
|
|
143
|
+
optimizeDeps: { rollupOptions: { transform: { jsx: { runtime: "automatic" } } } }
|
|
143
144
|
};
|
|
144
145
|
if (opts.jsxRuntime === "classic") return { esbuild: { jsx: "transform" } };
|
|
145
146
|
else return {
|
|
146
147
|
esbuild: {
|
|
147
148
|
jsx: "automatic",
|
|
148
|
-
jsxImportSource
|
|
149
|
+
jsxImportSource: opts.jsxImportSource
|
|
149
150
|
},
|
|
150
151
|
optimizeDeps: { esbuildOptions: { jsx: "automatic" } }
|
|
151
152
|
};
|
|
@@ -192,9 +193,18 @@ function viteReact(opts = {}) {
|
|
|
192
193
|
return newBabelOptions;
|
|
193
194
|
})();
|
|
194
195
|
const plugins = [...babelOptions.plugins];
|
|
196
|
+
let reactCompilerPlugin$1 = getReactCompilerPlugin(plugins);
|
|
197
|
+
if (reactCompilerPlugin$1 && ssr) {
|
|
198
|
+
plugins.splice(plugins.indexOf(reactCompilerPlugin$1), 1);
|
|
199
|
+
reactCompilerPlugin$1 = void 0;
|
|
200
|
+
}
|
|
201
|
+
if (Array.isArray(reactCompilerPlugin$1) && reactCompilerPlugin$1[1]?.compilationMode === "annotation" && !compilerAnnotationRE.test(code)) {
|
|
202
|
+
plugins.splice(plugins.indexOf(reactCompilerPlugin$1), 1);
|
|
203
|
+
reactCompilerPlugin$1 = void 0;
|
|
204
|
+
}
|
|
195
205
|
const isJSX = filepath.endsWith("x");
|
|
196
|
-
const useFastRefresh = !skipFastRefresh && !ssr && (isJSX || (opts.jsxRuntime === "classic" ? importReactRE.test(code) : code.includes(jsxImportDevRuntime) || code.includes(jsxImportRuntime)));
|
|
197
|
-
if (useFastRefresh
|
|
206
|
+
const useFastRefresh = !isRolldownVite && !skipFastRefresh && !ssr && (isJSX || (opts.jsxRuntime === "classic" ? importReactRE.test(code) : code.includes(jsxImportDevRuntime) || code.includes(jsxImportRuntime)));
|
|
207
|
+
if (useFastRefresh) plugins.push([await loadPlugin("react-refresh/babel"), { skipEnvCheck: true }]);
|
|
198
208
|
if (opts.jsxRuntime === "classic" && isJSX) {
|
|
199
209
|
if (!isProduction) plugins.push(await loadPlugin("@babel/plugin-transform-react-jsx-self"), await loadPlugin("@babel/plugin-transform-react-jsx-source"));
|
|
200
210
|
}
|
|
@@ -208,7 +218,7 @@ function viteReact(opts = {}) {
|
|
|
208
218
|
root: projectRoot,
|
|
209
219
|
filename: id,
|
|
210
220
|
sourceFileName: filepath,
|
|
211
|
-
retainLines:
|
|
221
|
+
retainLines: reactCompilerPlugin$1 ? false : !isProduction && isJSX && opts.jsxRuntime !== "classic",
|
|
212
222
|
parserOpts: {
|
|
213
223
|
...babelOptions.parserOpts,
|
|
214
224
|
sourceType: "module",
|
|
@@ -236,7 +246,7 @@ function viteReact(opts = {}) {
|
|
|
236
246
|
const viteRefreshWrapper = {
|
|
237
247
|
name: "vite:react:refresh-wrapper",
|
|
238
248
|
apply: "serve",
|
|
239
|
-
transform:
|
|
249
|
+
transform: {
|
|
240
250
|
filter: { id: {
|
|
241
251
|
include: makeIdFiltersToMatchWithQuery(include),
|
|
242
252
|
exclude: makeIdFiltersToMatchWithQuery(exclude)
|
|
@@ -247,13 +257,13 @@ function viteReact(opts = {}) {
|
|
|
247
257
|
const isJSX = filepath.endsWith("x");
|
|
248
258
|
const useFastRefresh = !skipFastRefresh && !ssr && (isJSX || code.includes(jsxImportDevRuntime) || code.includes(jsxImportRuntime));
|
|
249
259
|
if (!useFastRefresh) return;
|
|
250
|
-
const { code: newCode } = addRefreshWrapper(code, avoidSourceMapOption, "@vitejs/plugin-react", id);
|
|
260
|
+
const { code: newCode } = addRefreshWrapper(code, avoidSourceMapOption, "@vitejs/plugin-react", id, opts.reactRefreshHost);
|
|
251
261
|
return {
|
|
252
262
|
code: newCode,
|
|
253
263
|
map: null
|
|
254
264
|
};
|
|
255
265
|
}
|
|
256
|
-
}
|
|
266
|
+
}
|
|
257
267
|
};
|
|
258
268
|
const viteConfigPost = {
|
|
259
269
|
name: "vite:react:config-post",
|
|
@@ -303,8 +313,7 @@ function viteReact(opts = {}) {
|
|
|
303
313
|
};
|
|
304
314
|
return [
|
|
305
315
|
viteBabel,
|
|
306
|
-
viteRefreshWrapper,
|
|
307
|
-
viteConfigPost,
|
|
316
|
+
...isRolldownVite ? [viteRefreshWrapper, viteConfigPost] : [],
|
|
308
317
|
viteReactRefresh
|
|
309
318
|
];
|
|
310
319
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vitejs/plugin-react",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Evan You",
|
|
6
6
|
"description": "The default Vite plugin for React projects",
|
|
@@ -40,10 +40,10 @@
|
|
|
40
40
|
},
|
|
41
41
|
"homepage": "https://github.com/vitejs/vite-plugin-react/tree/main/packages/plugin-react#readme",
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@babel/core": "^7.28.
|
|
43
|
+
"@babel/core": "^7.28.3",
|
|
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.32",
|
|
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.2",
|
|
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.32",
|
|
59
|
+
"tsdown": "^0.14.1",
|
|
60
60
|
"vitest": "^3.2.4"
|
|
61
61
|
}
|
|
62
62
|
}
|