@vitejs/plugin-react 4.4.1 → 4.5.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.
Files changed (3) hide show
  1. package/dist/index.cjs +148 -94
  2. package/dist/index.mjs +135 -94
  3. package/package.json +2 -1
package/dist/index.cjs CHANGED
@@ -4,14 +4,29 @@ const node_path = require('node:path');
4
4
  const node_url = require('node:url');
5
5
  const node_fs = require('node:fs');
6
6
  const vite = require('vite');
7
+ const pluginutils = require('@rolldown/pluginutils');
7
8
 
8
9
  var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
10
+ function _interopNamespaceCompat(e) {
11
+ if (e && typeof e === 'object' && 'default' in e) return e;
12
+ const n = Object.create(null);
13
+ if (e) {
14
+ for (const k in e) {
15
+ n[k] = e[k];
16
+ }
17
+ }
18
+ n.default = e;
19
+ return n;
20
+ }
21
+
22
+ const vite__namespace = /*#__PURE__*/_interopNamespaceCompat(vite);
23
+
9
24
  const runtimePublicPath = "/@react-refresh";
10
25
  const reactCompRE = /extends\s+(?:React\.)?(?:Pure)?Component/;
11
- const refreshContentRE = /\$Refresh(?:Reg|Sig)\$\(/;
26
+ const refreshContentRE = /\$RefreshReg\$\(/;
12
27
  const preambleCode = `import { injectIntoGlobalHook } from "__BASE__${runtimePublicPath.slice(
13
28
  1
14
- )}"
29
+ )}";
15
30
  injectIntoGlobalHook(window);
16
31
  window.$RefreshReg$ = () => {};
17
32
  window.$RefreshSig$ = () => (type) => type;`;
@@ -93,7 +108,7 @@ function removeLineBreaksIfNeeded(code, enabled) {
93
108
  const silenceUseClientWarning = (userConfig) => ({
94
109
  rollupOptions: {
95
110
  onwarn(warning, defaultHandler) {
96
- if (warning.code === "MODULE_LEVEL_DIRECTIVE" && warning.message.includes("use client")) {
111
+ if (warning.code === "MODULE_LEVEL_DIRECTIVE" && (warning.message.includes("use client") || warning.message.includes("use server"))) {
97
112
  return;
98
113
  }
99
114
  if (warning.code === "SOURCEMAP_ERROR" && warning.message.includes("resolve original location") && warning.pos === 0) {
@@ -120,7 +135,9 @@ async function loadBabel() {
120
135
  const defaultIncludeRE = /\.[tj]sx?$/;
121
136
  const tsRE = /\.tsx?$/;
122
137
  function viteReact(opts = {}) {
123
- const filter = vite.createFilter(opts.include ?? defaultIncludeRE, opts.exclude);
138
+ const include = opts.include ?? defaultIncludeRE;
139
+ const exclude = opts.exclude;
140
+ const filter = vite.createFilter(include, exclude);
124
141
  const jsxImportSource = opts.jsxImportSource ?? "react";
125
142
  const jsxImportRuntime = `${jsxImportSource}/jsx-runtime`;
126
143
  const jsxImportDevRuntime = `${jsxImportSource}/jsx-dev-runtime`;
@@ -135,11 +152,25 @@ function viteReact(opts = {}) {
135
152
  enforce: "pre",
136
153
  config() {
137
154
  if (opts.jsxRuntime === "classic") {
138
- return {
139
- esbuild: {
140
- jsx: "transform"
141
- }
142
- };
155
+ if ("rolldownVersion" in vite__namespace) {
156
+ return {
157
+ oxc: {
158
+ jsx: {
159
+ runtime: "classic",
160
+ // disable __self and __source injection even in dev
161
+ // as this plugin injects them by babel and oxc will throw
162
+ // if development is enabled and those properties are already present
163
+ development: false
164
+ }
165
+ }
166
+ };
167
+ } else {
168
+ return {
169
+ esbuild: {
170
+ jsx: "transform"
171
+ }
172
+ };
173
+ }
143
174
  } else {
144
175
  return {
145
176
  esbuild: {
@@ -166,87 +197,98 @@ function viteReact(opts = {}) {
166
197
  };
167
198
  } else if (typeof opts.babel !== "function") {
168
199
  staticBabelOptions = createBabelOptions(opts.babel);
200
+ if (canSkipBabel(staticBabelOptions.plugins, staticBabelOptions) && skipFastRefresh && (opts.jsxRuntime === "classic" ? isProduction : true)) {
201
+ delete viteBabel.transform;
202
+ }
169
203
  }
170
204
  },
171
- async transform(code, id, options) {
172
- if (id.includes("/node_modules/")) return;
173
- const [filepath] = id.split("?");
174
- if (!filter(filepath)) return;
175
- const ssr = options?.ssr === true;
176
- const babelOptions = (() => {
177
- if (staticBabelOptions) return staticBabelOptions;
178
- const newBabelOptions = createBabelOptions(
179
- typeof opts.babel === "function" ? opts.babel(id, { ssr }) : opts.babel
180
- );
181
- runPluginOverrides?.(newBabelOptions, { id, ssr });
182
- return newBabelOptions;
183
- })();
184
- const plugins = [...babelOptions.plugins];
185
- const isJSX = filepath.endsWith("x");
186
- const useFastRefresh = !skipFastRefresh && !ssr && (isJSX || (opts.jsxRuntime === "classic" ? importReactRE.test(code) : code.includes(jsxImportDevRuntime) || code.includes(jsxImportRuntime)));
187
- if (useFastRefresh) {
188
- plugins.push([
189
- await loadPlugin("react-refresh/babel"),
190
- { skipEnvCheck: true }
191
- ]);
192
- }
193
- if (opts.jsxRuntime === "classic" && isJSX && // OXC injects self and source so these plugins are not needed for rolldown-vite
194
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
195
- // @ts-ignore -- this.meta.rolldownVersion only exists in rolldown-vite
196
- !this.meta.rolldownVersion) {
197
- if (!isProduction) {
198
- plugins.push(
199
- await loadPlugin("@babel/plugin-transform-react-jsx-self"),
200
- await loadPlugin("@babel/plugin-transform-react-jsx-source")
205
+ transform: {
206
+ filter: {
207
+ id: {
208
+ include: pluginutils.makeIdFiltersToMatchWithQuery(include),
209
+ exclude: [
210
+ ...exclude ? pluginutils.makeIdFiltersToMatchWithQuery(ensureArray(exclude)) : [],
211
+ /\/node_modules\//
212
+ ]
213
+ }
214
+ },
215
+ async handler(code, id, options) {
216
+ if (id.includes("/node_modules/")) return;
217
+ const [filepath] = id.split("?");
218
+ if (!filter(filepath)) return;
219
+ const ssr = options?.ssr === true;
220
+ const babelOptions = (() => {
221
+ if (staticBabelOptions) return staticBabelOptions;
222
+ const newBabelOptions = createBabelOptions(
223
+ typeof opts.babel === "function" ? opts.babel(id, { ssr }) : opts.babel
201
224
  );
225
+ runPluginOverrides?.(newBabelOptions, { id, ssr });
226
+ return newBabelOptions;
227
+ })();
228
+ const plugins = [...babelOptions.plugins];
229
+ const isJSX = filepath.endsWith("x");
230
+ const useFastRefresh = !skipFastRefresh && !ssr && (isJSX || (opts.jsxRuntime === "classic" ? importReactRE.test(code) : code.includes(jsxImportDevRuntime) || code.includes(jsxImportRuntime)));
231
+ if (useFastRefresh) {
232
+ plugins.push([
233
+ await loadPlugin("react-refresh/babel"),
234
+ { skipEnvCheck: true }
235
+ ]);
202
236
  }
203
- }
204
- if (!plugins.length && !babelOptions.presets.length && !babelOptions.configFile && !babelOptions.babelrc) {
205
- return;
206
- }
207
- const parserPlugins = [...babelOptions.parserOpts.plugins];
208
- if (!filepath.endsWith(".ts")) {
209
- parserPlugins.push("jsx");
210
- }
211
- if (tsRE.test(filepath)) {
212
- parserPlugins.push("typescript");
213
- }
214
- const babel2 = await loadBabel();
215
- const result = await babel2.transformAsync(code, {
216
- ...babelOptions,
217
- root: projectRoot,
218
- filename: id,
219
- sourceFileName: filepath,
220
- // Required for esbuild.jsxDev to provide correct line numbers
221
- // This creates issues the react compiler because the re-order is too important
222
- // People should use @babel/plugin-transform-react-jsx-development to get back good line numbers
223
- retainLines: getReactCompilerPlugin(plugins) != null ? false : !isProduction && isJSX && opts.jsxRuntime !== "classic",
224
- parserOpts: {
225
- ...babelOptions.parserOpts,
226
- sourceType: "module",
227
- allowAwaitOutsideFunction: true,
228
- plugins: parserPlugins
229
- },
230
- generatorOpts: {
231
- ...babelOptions.generatorOpts,
232
- // import attributes parsing available without plugin since 7.26
233
- importAttributesKeyword: "with",
234
- decoratorsBeforeExport: true
235
- },
236
- plugins,
237
- sourceMaps: true
238
- });
239
- if (result) {
240
- if (!useFastRefresh) {
241
- return { code: result.code, map: result.map };
237
+ if (opts.jsxRuntime === "classic" && isJSX) {
238
+ if (!isProduction) {
239
+ plugins.push(
240
+ await loadPlugin("@babel/plugin-transform-react-jsx-self"),
241
+ await loadPlugin("@babel/plugin-transform-react-jsx-source")
242
+ );
243
+ }
244
+ }
245
+ if (canSkipBabel(plugins, babelOptions)) {
246
+ return;
247
+ }
248
+ const parserPlugins = [...babelOptions.parserOpts.plugins];
249
+ if (!filepath.endsWith(".ts")) {
250
+ parserPlugins.push("jsx");
251
+ }
252
+ if (tsRE.test(filepath)) {
253
+ parserPlugins.push("typescript");
254
+ }
255
+ const babel2 = await loadBabel();
256
+ const result = await babel2.transformAsync(code, {
257
+ ...babelOptions,
258
+ root: projectRoot,
259
+ filename: id,
260
+ sourceFileName: filepath,
261
+ // Required for esbuild.jsxDev to provide correct line numbers
262
+ // This creates issues the react compiler because the re-order is too important
263
+ // People should use @babel/plugin-transform-react-jsx-development to get back good line numbers
264
+ retainLines: getReactCompilerPlugin(plugins) != null ? false : !isProduction && isJSX && opts.jsxRuntime !== "classic",
265
+ parserOpts: {
266
+ ...babelOptions.parserOpts,
267
+ sourceType: "module",
268
+ allowAwaitOutsideFunction: true,
269
+ plugins: parserPlugins
270
+ },
271
+ generatorOpts: {
272
+ ...babelOptions.generatorOpts,
273
+ // import attributes parsing available without plugin since 7.26
274
+ importAttributesKeyword: "with",
275
+ decoratorsBeforeExport: true
276
+ },
277
+ plugins,
278
+ sourceMaps: true
279
+ });
280
+ if (result) {
281
+ if (!useFastRefresh) {
282
+ return { code: result.code, map: result.map };
283
+ }
284
+ return addRefreshWrapper(
285
+ result.code,
286
+ result.map,
287
+ "@vitejs/plugin-react",
288
+ id,
289
+ opts.reactRefreshHost
290
+ );
242
291
  }
243
- return addRefreshWrapper(
244
- result.code,
245
- result.map,
246
- "@vitejs/plugin-react",
247
- id,
248
- opts.reactRefreshHost
249
- );
250
292
  }
251
293
  }
252
294
  };
@@ -274,17 +316,23 @@ function viteReact(opts = {}) {
274
316
  dedupe: ["react", "react-dom"]
275
317
  }
276
318
  }),
277
- resolveId(id) {
278
- if (id === runtimePublicPath) {
279
- return id;
319
+ resolveId: {
320
+ filter: { id: pluginutils.exactRegex(runtimePublicPath) },
321
+ handler(id) {
322
+ if (id === runtimePublicPath) {
323
+ return id;
324
+ }
280
325
  }
281
326
  },
282
- load(id) {
283
- if (id === runtimePublicPath) {
284
- return node_fs.readFileSync(refreshRuntimePath, "utf-8").replace(
285
- /__README_URL__/g,
286
- "https://github.com/vitejs/vite-plugin-react/tree/main/packages/plugin-react"
287
- );
327
+ load: {
328
+ filter: { id: pluginutils.exactRegex(runtimePublicPath) },
329
+ handler(id) {
330
+ if (id === runtimePublicPath) {
331
+ return node_fs.readFileSync(refreshRuntimePath, "utf-8").replace(
332
+ /__README_URL__/g,
333
+ "https://github.com/vitejs/vite-plugin-react/tree/main/packages/plugin-react"
334
+ );
335
+ }
288
336
  }
289
337
  },
290
338
  transformIndexHtml(_, config) {
@@ -301,6 +349,9 @@ function viteReact(opts = {}) {
301
349
  return [viteBabel, viteReactRefresh];
302
350
  }
303
351
  viteReact.preambleCode = preambleCode;
352
+ function canSkipBabel(plugins, babelOptions) {
353
+ return !(plugins.length || babelOptions.presets.length || babelOptions.configFile || babelOptions.babelrc);
354
+ }
304
355
  const loadedPlugin = /* @__PURE__ */ new Map();
305
356
  function loadPlugin(path) {
306
357
  const cached = loadedPlugin.get(path);
@@ -345,6 +396,9 @@ function getReactCompilerRuntimeModule(plugin) {
345
396
  }
346
397
  return moduleName;
347
398
  }
399
+ function ensureArray(value) {
400
+ return Array.isArray(value) ? value : [value];
401
+ }
348
402
 
349
403
  module.exports = viteReact;
350
404
  module.exports.default = viteReact;
package/dist/index.mjs CHANGED
@@ -1,14 +1,16 @@
1
1
  import { dirname, join } from 'node:path';
2
2
  import { fileURLToPath } from 'node:url';
3
3
  import { readFileSync } from 'node:fs';
4
+ import * as vite from 'vite';
4
5
  import { createFilter } from 'vite';
6
+ import { makeIdFiltersToMatchWithQuery, exactRegex } from '@rolldown/pluginutils';
5
7
 
6
8
  const runtimePublicPath = "/@react-refresh";
7
9
  const reactCompRE = /extends\s+(?:React\.)?(?:Pure)?Component/;
8
- const refreshContentRE = /\$Refresh(?:Reg|Sig)\$\(/;
10
+ const refreshContentRE = /\$RefreshReg\$\(/;
9
11
  const preambleCode = `import { injectIntoGlobalHook } from "__BASE__${runtimePublicPath.slice(
10
12
  1
11
- )}"
13
+ )}";
12
14
  injectIntoGlobalHook(window);
13
15
  window.$RefreshReg$ = () => {};
14
16
  window.$RefreshSig$ = () => (type) => type;`;
@@ -90,7 +92,7 @@ function removeLineBreaksIfNeeded(code, enabled) {
90
92
  const silenceUseClientWarning = (userConfig) => ({
91
93
  rollupOptions: {
92
94
  onwarn(warning, defaultHandler) {
93
- if (warning.code === "MODULE_LEVEL_DIRECTIVE" && warning.message.includes("use client")) {
95
+ if (warning.code === "MODULE_LEVEL_DIRECTIVE" && (warning.message.includes("use client") || warning.message.includes("use server"))) {
94
96
  return;
95
97
  }
96
98
  if (warning.code === "SOURCEMAP_ERROR" && warning.message.includes("resolve original location") && warning.pos === 0) {
@@ -117,7 +119,9 @@ async function loadBabel() {
117
119
  const defaultIncludeRE = /\.[tj]sx?$/;
118
120
  const tsRE = /\.tsx?$/;
119
121
  function viteReact(opts = {}) {
120
- const filter = createFilter(opts.include ?? defaultIncludeRE, opts.exclude);
122
+ const include = opts.include ?? defaultIncludeRE;
123
+ const exclude = opts.exclude;
124
+ const filter = createFilter(include, exclude);
121
125
  const jsxImportSource = opts.jsxImportSource ?? "react";
122
126
  const jsxImportRuntime = `${jsxImportSource}/jsx-runtime`;
123
127
  const jsxImportDevRuntime = `${jsxImportSource}/jsx-dev-runtime`;
@@ -132,11 +136,25 @@ function viteReact(opts = {}) {
132
136
  enforce: "pre",
133
137
  config() {
134
138
  if (opts.jsxRuntime === "classic") {
135
- return {
136
- esbuild: {
137
- jsx: "transform"
138
- }
139
- };
139
+ if ("rolldownVersion" in vite) {
140
+ return {
141
+ oxc: {
142
+ jsx: {
143
+ runtime: "classic",
144
+ // disable __self and __source injection even in dev
145
+ // as this plugin injects them by babel and oxc will throw
146
+ // if development is enabled and those properties are already present
147
+ development: false
148
+ }
149
+ }
150
+ };
151
+ } else {
152
+ return {
153
+ esbuild: {
154
+ jsx: "transform"
155
+ }
156
+ };
157
+ }
140
158
  } else {
141
159
  return {
142
160
  esbuild: {
@@ -163,87 +181,98 @@ function viteReact(opts = {}) {
163
181
  };
164
182
  } else if (typeof opts.babel !== "function") {
165
183
  staticBabelOptions = createBabelOptions(opts.babel);
184
+ if (canSkipBabel(staticBabelOptions.plugins, staticBabelOptions) && skipFastRefresh && (opts.jsxRuntime === "classic" ? isProduction : true)) {
185
+ delete viteBabel.transform;
186
+ }
166
187
  }
167
188
  },
168
- async transform(code, id, options) {
169
- if (id.includes("/node_modules/")) return;
170
- const [filepath] = id.split("?");
171
- if (!filter(filepath)) return;
172
- const ssr = options?.ssr === true;
173
- const babelOptions = (() => {
174
- if (staticBabelOptions) return staticBabelOptions;
175
- const newBabelOptions = createBabelOptions(
176
- typeof opts.babel === "function" ? opts.babel(id, { ssr }) : opts.babel
177
- );
178
- runPluginOverrides?.(newBabelOptions, { id, ssr });
179
- return newBabelOptions;
180
- })();
181
- const plugins = [...babelOptions.plugins];
182
- const isJSX = filepath.endsWith("x");
183
- const useFastRefresh = !skipFastRefresh && !ssr && (isJSX || (opts.jsxRuntime === "classic" ? importReactRE.test(code) : code.includes(jsxImportDevRuntime) || code.includes(jsxImportRuntime)));
184
- if (useFastRefresh) {
185
- plugins.push([
186
- await loadPlugin("react-refresh/babel"),
187
- { skipEnvCheck: true }
188
- ]);
189
- }
190
- if (opts.jsxRuntime === "classic" && isJSX && // OXC injects self and source so these plugins are not needed for rolldown-vite
191
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
192
- // @ts-ignore -- this.meta.rolldownVersion only exists in rolldown-vite
193
- !this.meta.rolldownVersion) {
194
- if (!isProduction) {
195
- plugins.push(
196
- await loadPlugin("@babel/plugin-transform-react-jsx-self"),
197
- await loadPlugin("@babel/plugin-transform-react-jsx-source")
189
+ transform: {
190
+ filter: {
191
+ id: {
192
+ include: makeIdFiltersToMatchWithQuery(include),
193
+ exclude: [
194
+ ...exclude ? makeIdFiltersToMatchWithQuery(ensureArray(exclude)) : [],
195
+ /\/node_modules\//
196
+ ]
197
+ }
198
+ },
199
+ async handler(code, id, options) {
200
+ if (id.includes("/node_modules/")) return;
201
+ const [filepath] = id.split("?");
202
+ if (!filter(filepath)) return;
203
+ const ssr = options?.ssr === true;
204
+ const babelOptions = (() => {
205
+ if (staticBabelOptions) return staticBabelOptions;
206
+ const newBabelOptions = createBabelOptions(
207
+ typeof opts.babel === "function" ? opts.babel(id, { ssr }) : opts.babel
198
208
  );
209
+ runPluginOverrides?.(newBabelOptions, { id, ssr });
210
+ return newBabelOptions;
211
+ })();
212
+ const plugins = [...babelOptions.plugins];
213
+ const isJSX = filepath.endsWith("x");
214
+ const useFastRefresh = !skipFastRefresh && !ssr && (isJSX || (opts.jsxRuntime === "classic" ? importReactRE.test(code) : code.includes(jsxImportDevRuntime) || code.includes(jsxImportRuntime)));
215
+ if (useFastRefresh) {
216
+ plugins.push([
217
+ await loadPlugin("react-refresh/babel"),
218
+ { skipEnvCheck: true }
219
+ ]);
199
220
  }
200
- }
201
- if (!plugins.length && !babelOptions.presets.length && !babelOptions.configFile && !babelOptions.babelrc) {
202
- return;
203
- }
204
- const parserPlugins = [...babelOptions.parserOpts.plugins];
205
- if (!filepath.endsWith(".ts")) {
206
- parserPlugins.push("jsx");
207
- }
208
- if (tsRE.test(filepath)) {
209
- parserPlugins.push("typescript");
210
- }
211
- const babel2 = await loadBabel();
212
- const result = await babel2.transformAsync(code, {
213
- ...babelOptions,
214
- root: projectRoot,
215
- filename: id,
216
- sourceFileName: filepath,
217
- // Required for esbuild.jsxDev to provide correct line numbers
218
- // This creates issues the react compiler because the re-order is too important
219
- // People should use @babel/plugin-transform-react-jsx-development to get back good line numbers
220
- retainLines: getReactCompilerPlugin(plugins) != null ? false : !isProduction && isJSX && opts.jsxRuntime !== "classic",
221
- parserOpts: {
222
- ...babelOptions.parserOpts,
223
- sourceType: "module",
224
- allowAwaitOutsideFunction: true,
225
- plugins: parserPlugins
226
- },
227
- generatorOpts: {
228
- ...babelOptions.generatorOpts,
229
- // import attributes parsing available without plugin since 7.26
230
- importAttributesKeyword: "with",
231
- decoratorsBeforeExport: true
232
- },
233
- plugins,
234
- sourceMaps: true
235
- });
236
- if (result) {
237
- if (!useFastRefresh) {
238
- return { code: result.code, map: result.map };
221
+ if (opts.jsxRuntime === "classic" && isJSX) {
222
+ if (!isProduction) {
223
+ plugins.push(
224
+ await loadPlugin("@babel/plugin-transform-react-jsx-self"),
225
+ await loadPlugin("@babel/plugin-transform-react-jsx-source")
226
+ );
227
+ }
228
+ }
229
+ if (canSkipBabel(plugins, babelOptions)) {
230
+ return;
231
+ }
232
+ const parserPlugins = [...babelOptions.parserOpts.plugins];
233
+ if (!filepath.endsWith(".ts")) {
234
+ parserPlugins.push("jsx");
235
+ }
236
+ if (tsRE.test(filepath)) {
237
+ parserPlugins.push("typescript");
238
+ }
239
+ const babel2 = await loadBabel();
240
+ const result = await babel2.transformAsync(code, {
241
+ ...babelOptions,
242
+ root: projectRoot,
243
+ filename: id,
244
+ sourceFileName: filepath,
245
+ // Required for esbuild.jsxDev to provide correct line numbers
246
+ // This creates issues the react compiler because the re-order is too important
247
+ // People should use @babel/plugin-transform-react-jsx-development to get back good line numbers
248
+ retainLines: getReactCompilerPlugin(plugins) != null ? false : !isProduction && isJSX && opts.jsxRuntime !== "classic",
249
+ parserOpts: {
250
+ ...babelOptions.parserOpts,
251
+ sourceType: "module",
252
+ allowAwaitOutsideFunction: true,
253
+ plugins: parserPlugins
254
+ },
255
+ generatorOpts: {
256
+ ...babelOptions.generatorOpts,
257
+ // import attributes parsing available without plugin since 7.26
258
+ importAttributesKeyword: "with",
259
+ decoratorsBeforeExport: true
260
+ },
261
+ plugins,
262
+ sourceMaps: true
263
+ });
264
+ if (result) {
265
+ if (!useFastRefresh) {
266
+ return { code: result.code, map: result.map };
267
+ }
268
+ return addRefreshWrapper(
269
+ result.code,
270
+ result.map,
271
+ "@vitejs/plugin-react",
272
+ id,
273
+ opts.reactRefreshHost
274
+ );
239
275
  }
240
- return addRefreshWrapper(
241
- result.code,
242
- result.map,
243
- "@vitejs/plugin-react",
244
- id,
245
- opts.reactRefreshHost
246
- );
247
276
  }
248
277
  }
249
278
  };
@@ -271,17 +300,23 @@ function viteReact(opts = {}) {
271
300
  dedupe: ["react", "react-dom"]
272
301
  }
273
302
  }),
274
- resolveId(id) {
275
- if (id === runtimePublicPath) {
276
- return id;
303
+ resolveId: {
304
+ filter: { id: exactRegex(runtimePublicPath) },
305
+ handler(id) {
306
+ if (id === runtimePublicPath) {
307
+ return id;
308
+ }
277
309
  }
278
310
  },
279
- load(id) {
280
- if (id === runtimePublicPath) {
281
- return readFileSync(refreshRuntimePath, "utf-8").replace(
282
- /__README_URL__/g,
283
- "https://github.com/vitejs/vite-plugin-react/tree/main/packages/plugin-react"
284
- );
311
+ load: {
312
+ filter: { id: exactRegex(runtimePublicPath) },
313
+ handler(id) {
314
+ if (id === runtimePublicPath) {
315
+ return readFileSync(refreshRuntimePath, "utf-8").replace(
316
+ /__README_URL__/g,
317
+ "https://github.com/vitejs/vite-plugin-react/tree/main/packages/plugin-react"
318
+ );
319
+ }
285
320
  }
286
321
  },
287
322
  transformIndexHtml(_, config) {
@@ -298,6 +333,9 @@ function viteReact(opts = {}) {
298
333
  return [viteBabel, viteReactRefresh];
299
334
  }
300
335
  viteReact.preambleCode = preambleCode;
336
+ function canSkipBabel(plugins, babelOptions) {
337
+ return !(plugins.length || babelOptions.presets.length || babelOptions.configFile || babelOptions.babelrc);
338
+ }
301
339
  const loadedPlugin = /* @__PURE__ */ new Map();
302
340
  function loadPlugin(path) {
303
341
  const cached = loadedPlugin.get(path);
@@ -342,5 +380,8 @@ function getReactCompilerRuntimeModule(plugin) {
342
380
  }
343
381
  return moduleName;
344
382
  }
383
+ function ensureArray(value) {
384
+ return Array.isArray(value) ? value : [value];
385
+ }
345
386
 
346
387
  export { viteReact as default };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vitejs/plugin-react",
3
- "version": "4.4.1",
3
+ "version": "4.5.1",
4
4
  "license": "MIT",
5
5
  "author": "Evan You",
6
6
  "description": "The default Vite plugin for React projects",
@@ -51,6 +51,7 @@
51
51
  "@babel/core": "^7.26.10",
52
52
  "@babel/plugin-transform-react-jsx-self": "^7.25.9",
53
53
  "@babel/plugin-transform-react-jsx-source": "^7.25.9",
54
+ "@rolldown/pluginutils": "1.0.0-beta.9",
54
55
  "@types/babel__core": "^7.20.5",
55
56
  "react-refresh": "^0.17.0"
56
57
  },