@vitejs/plugin-react 4.3.2 → 4.3.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/dist/index.cjs CHANGED
@@ -198,7 +198,7 @@ function viteReact(opts = {}) {
198
198
  // Required for esbuild.jsxDev to provide correct line numbers
199
199
  // This crates issues the react compiler because the re-order is too important
200
200
  // People should use @babel/plugin-transform-react-jsx-development to get back good line numbers
201
- retainLines: hasCompiler(plugins) ? false : !isProduction && isJSX && opts.jsxRuntime !== "classic",
201
+ retainLines: getReactCompilerPlugin(plugins) != null ? false : !isProduction && isJSX && opts.jsxRuntime !== "classic",
202
202
  parserOpts: {
203
203
  ...babelOptions.parserOpts,
204
204
  sourceType: "module",
@@ -207,6 +207,8 @@ function viteReact(opts = {}) {
207
207
  },
208
208
  generatorOpts: {
209
209
  ...babelOptions.generatorOpts,
210
+ // import attributes parsing available without plugin since 7.26
211
+ importAttributesKeyword: "with",
210
212
  decoratorsBeforeExport: true
211
213
  },
212
214
  plugins,
@@ -225,10 +227,17 @@ function viteReact(opts = {}) {
225
227
  }
226
228
  }
227
229
  };
228
- const dependencies = ["react", jsxImportDevRuntime, jsxImportRuntime];
230
+ const dependencies = [
231
+ "react",
232
+ "react-dom",
233
+ jsxImportDevRuntime,
234
+ jsxImportRuntime
235
+ ];
229
236
  const staticBabelPlugins = typeof opts.babel === "object" ? opts.babel?.plugins ?? [] : [];
230
- if (hasCompilerWithDefaultRuntime(staticBabelPlugins)) {
231
- dependencies.push("react/compiler-runtime");
237
+ const reactCompilerPlugin = getReactCompilerPlugin(staticBabelPlugins);
238
+ if (reactCompilerPlugin != null) {
239
+ const reactCompilerRuntimeModule = getReactCompilerRuntimeModule(reactCompilerPlugin);
240
+ dependencies.push(reactCompilerRuntimeModule);
232
241
  }
233
242
  const viteReactRefresh = {
234
243
  name: "vite:react-refresh",
@@ -313,15 +322,21 @@ function createBabelOptions(rawOptions) {
313
322
  function defined(value) {
314
323
  return value !== void 0;
315
324
  }
316
- function hasCompiler(plugins) {
317
- return plugins.some(
325
+ function getReactCompilerPlugin(plugins) {
326
+ return plugins.find(
318
327
  (p) => p === "babel-plugin-react-compiler" || Array.isArray(p) && p[0] === "babel-plugin-react-compiler"
319
328
  );
320
329
  }
321
- function hasCompilerWithDefaultRuntime(plugins) {
322
- return plugins.some(
323
- (p) => p === "babel-plugin-react-compiler" || Array.isArray(p) && p[0] === "babel-plugin-react-compiler" && p[1]?.runtimeModule === void 0
324
- );
330
+ function getReactCompilerRuntimeModule(plugin) {
331
+ let moduleName = "react/compiler-runtime";
332
+ if (Array.isArray(plugin)) {
333
+ if (plugin[1]?.target === "17" || plugin[1]?.target === "18") {
334
+ moduleName = "react-compiler-runtime";
335
+ } else if (typeof plugin[1]?.runtimeModule === "string") {
336
+ moduleName = plugin[1]?.runtimeModule;
337
+ }
338
+ }
339
+ return moduleName;
325
340
  }
326
341
 
327
342
  module.exports = viteReact;
package/dist/index.mjs CHANGED
@@ -190,7 +190,7 @@ function viteReact(opts = {}) {
190
190
  // Required for esbuild.jsxDev to provide correct line numbers
191
191
  // This crates issues the react compiler because the re-order is too important
192
192
  // People should use @babel/plugin-transform-react-jsx-development to get back good line numbers
193
- retainLines: hasCompiler(plugins) ? false : !isProduction && isJSX && opts.jsxRuntime !== "classic",
193
+ retainLines: getReactCompilerPlugin(plugins) != null ? false : !isProduction && isJSX && opts.jsxRuntime !== "classic",
194
194
  parserOpts: {
195
195
  ...babelOptions.parserOpts,
196
196
  sourceType: "module",
@@ -199,6 +199,8 @@ function viteReact(opts = {}) {
199
199
  },
200
200
  generatorOpts: {
201
201
  ...babelOptions.generatorOpts,
202
+ // import attributes parsing available without plugin since 7.26
203
+ importAttributesKeyword: "with",
202
204
  decoratorsBeforeExport: true
203
205
  },
204
206
  plugins,
@@ -217,10 +219,17 @@ function viteReact(opts = {}) {
217
219
  }
218
220
  }
219
221
  };
220
- const dependencies = ["react", jsxImportDevRuntime, jsxImportRuntime];
222
+ const dependencies = [
223
+ "react",
224
+ "react-dom",
225
+ jsxImportDevRuntime,
226
+ jsxImportRuntime
227
+ ];
221
228
  const staticBabelPlugins = typeof opts.babel === "object" ? opts.babel?.plugins ?? [] : [];
222
- if (hasCompilerWithDefaultRuntime(staticBabelPlugins)) {
223
- dependencies.push("react/compiler-runtime");
229
+ const reactCompilerPlugin = getReactCompilerPlugin(staticBabelPlugins);
230
+ if (reactCompilerPlugin != null) {
231
+ const reactCompilerRuntimeModule = getReactCompilerRuntimeModule(reactCompilerPlugin);
232
+ dependencies.push(reactCompilerRuntimeModule);
224
233
  }
225
234
  const viteReactRefresh = {
226
235
  name: "vite:react-refresh",
@@ -305,15 +314,21 @@ function createBabelOptions(rawOptions) {
305
314
  function defined(value) {
306
315
  return value !== void 0;
307
316
  }
308
- function hasCompiler(plugins) {
309
- return plugins.some(
317
+ function getReactCompilerPlugin(plugins) {
318
+ return plugins.find(
310
319
  (p) => p === "babel-plugin-react-compiler" || Array.isArray(p) && p[0] === "babel-plugin-react-compiler"
311
320
  );
312
321
  }
313
- function hasCompilerWithDefaultRuntime(plugins) {
314
- return plugins.some(
315
- (p) => p === "babel-plugin-react-compiler" || Array.isArray(p) && p[0] === "babel-plugin-react-compiler" && p[1]?.runtimeModule === void 0
316
- );
322
+ function getReactCompilerRuntimeModule(plugin) {
323
+ let moduleName = "react/compiler-runtime";
324
+ if (Array.isArray(plugin)) {
325
+ if (plugin[1]?.target === "17" || plugin[1]?.target === "18") {
326
+ moduleName = "react-compiler-runtime";
327
+ } else if (typeof plugin[1]?.runtimeModule === "string") {
328
+ moduleName = plugin[1]?.runtimeModule;
329
+ }
330
+ }
331
+ return moduleName;
317
332
  }
318
333
 
319
334
  export { viteReact as default };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vitejs/plugin-react",
3
- "version": "4.3.2",
3
+ "version": "4.3.4",
4
4
  "license": "MIT",
5
5
  "author": "Evan You",
6
6
  "contributors": [
@@ -38,14 +38,14 @@
38
38
  },
39
39
  "homepage": "https://github.com/vitejs/vite-plugin-react/tree/main/packages/plugin-react#readme",
40
40
  "dependencies": {
41
- "@babel/core": "^7.25.2",
42
- "@babel/plugin-transform-react-jsx-self": "^7.24.7",
43
- "@babel/plugin-transform-react-jsx-source": "^7.24.7",
41
+ "@babel/core": "^7.26.0",
42
+ "@babel/plugin-transform-react-jsx-self": "^7.25.9",
43
+ "@babel/plugin-transform-react-jsx-source": "^7.25.9",
44
44
  "@types/babel__core": "^7.20.5",
45
45
  "react-refresh": "^0.14.2"
46
46
  },
47
47
  "peerDependencies": {
48
- "vite": "^4.2.0 || ^5.0.0"
48
+ "vite": "^4.2.0 || ^5.0.0 || ^6.0.0"
49
49
  },
50
50
  "devDependencies": {
51
51
  "unbuild": "^2.0.0"