@vitejs/plugin-react 5.0.0 → 5.0.2

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.
Files changed (3) hide show
  1. package/README.md +1 -1
  2. package/dist/index.js +21 -12
  3. package/package.json +6 -6
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. Default to `'react'`
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: { mode: "automatic" } } }
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
  };
@@ -161,7 +162,7 @@ function viteReact(opts = {}) {
161
162
  };
162
163
  else if (typeof opts.babel !== "function") {
163
164
  staticBabelOptions = createBabelOptions(opts.babel);
164
- if (canSkipBabel(staticBabelOptions.plugins, staticBabelOptions) && skipFastRefresh && (opts.jsxRuntime === "classic" ? isProduction : true)) delete viteBabel.transform;
165
+ if ((isRolldownVite || skipFastRefresh) && canSkipBabel(staticBabelOptions.plugins, staticBabelOptions) && (opts.jsxRuntime === "classic" ? isProduction : true)) delete viteBabel.transform;
165
166
  }
166
167
  },
167
168
  options(options) {
@@ -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 && !isRolldownVite) plugins.push([await loadPlugin("react-refresh/babel"), { skipEnvCheck: true }]);
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: getReactCompilerPlugin(plugins) != null ? false : !isProduction && isJSX && opts.jsxRuntime !== "classic",
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: isRolldownVite ? {
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
- } : void 0
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.0",
3
+ "version": "5.0.2",
4
4
  "license": "MIT",
5
5
  "author": "Evan You",
6
6
  "description": "The default Vite plugin for React projects",
@@ -22,7 +22,7 @@
22
22
  "type": "module",
23
23
  "exports": "./dist/index.js",
24
24
  "scripts": {
25
- "dev": "tsdown --watch",
25
+ "dev": "tsdown --watch ./src --watch ../common",
26
26
  "build": "tsdown",
27
27
  "prepublishOnly": "npm run build",
28
28
  "test-unit": "vitest run"
@@ -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.0",
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.30",
46
+ "@rolldown/pluginutils": "1.0.0-beta.34",
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.30",
59
- "tsdown": "^0.13.2",
58
+ "rolldown": "1.0.0-beta.34",
59
+ "tsdown": "^0.14.2",
60
60
  "vitest": "^3.2.4"
61
61
  }
62
62
  }