@vitejs/plugin-react 4.5.2 → 4.7.0

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
@@ -1,48 +1,55 @@
1
- 'use strict';
1
+ //#region rolldown:runtime
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
10
+ key = keys[i];
11
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
12
+ get: ((k) => from[k]).bind(null, key),
13
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
14
+ });
15
+ }
16
+ return to;
17
+ };
18
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
19
+ value: mod,
20
+ enumerable: true
21
+ }) : target, mod));
2
22
 
3
- const node_path = require('node:path');
4
- const node_url = require('node:url');
5
- const node_fs = require('node:fs');
6
- const vite = require('vite');
7
- const pluginutils = require('@rolldown/pluginutils');
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
+ //#endregion
24
+ const node_path = __toESM(require("node:path"));
25
+ const node_url = __toESM(require("node:url"));
26
+ const node_fs = __toESM(require("node:fs"));
27
+ const vite = __toESM(require("vite"));
28
+ const __rolldown_pluginutils = __toESM(require("@rolldown/pluginutils"));
23
29
 
30
+ //#region ../common/refresh-utils.ts
24
31
  const runtimePublicPath = "/@react-refresh";
25
32
  const reactCompRE = /extends\s+(?:React\.)?(?:Pure)?Component/;
26
33
  const refreshContentRE = /\$RefreshReg\$\(/;
27
- const preambleCode = `import { injectIntoGlobalHook } from "__BASE__${runtimePublicPath.slice(
28
- 1
29
- )}";
34
+ const preambleCode = `import { injectIntoGlobalHook } from "__BASE__${runtimePublicPath.slice(1)}";
30
35
  injectIntoGlobalHook(window);
31
36
  window.$RefreshReg$ = () => {};
32
37
  window.$RefreshSig$ = () => (type) => type;`;
33
38
  const getPreambleCode = (base) => preambleCode.replace("__BASE__", base);
34
39
  const avoidSourceMapOption = Symbol();
35
40
  function addRefreshWrapper(code, map, pluginName, id, reactRefreshHost = "") {
36
- const hasRefresh = refreshContentRE.test(code);
37
- const onlyReactComp = !hasRefresh && reactCompRE.test(code);
38
- const normalizedMap = map === avoidSourceMapOption ? null : map;
39
- if (!hasRefresh && !onlyReactComp) return { code, map: normalizedMap };
40
- const avoidSourceMap = map === avoidSourceMapOption;
41
- const newMap = typeof normalizedMap === "string" ? JSON.parse(normalizedMap) : normalizedMap;
42
- let newCode = code;
43
- if (hasRefresh) {
44
- const refreshHead = removeLineBreaksIfNeeded(
45
- `let prevRefreshReg;
41
+ const hasRefresh = refreshContentRE.test(code);
42
+ const onlyReactComp = !hasRefresh && reactCompRE.test(code);
43
+ const normalizedMap = map === avoidSourceMapOption ? null : map;
44
+ if (!hasRefresh && !onlyReactComp) return {
45
+ code,
46
+ map: normalizedMap
47
+ };
48
+ const avoidSourceMap = map === avoidSourceMapOption;
49
+ const newMap = typeof normalizedMap === "string" ? JSON.parse(normalizedMap) : normalizedMap;
50
+ let newCode = code;
51
+ if (hasRefresh) {
52
+ const refreshHead = removeLineBreaksIfNeeded(`let prevRefreshReg;
46
53
  let prevRefreshSig;
47
54
 
48
55
  if (import.meta.hot && !inWebWorker) {
@@ -58,352 +65,279 @@ if (import.meta.hot && !inWebWorker) {
58
65
  window.$RefreshSig$ = RefreshRuntime.createSignatureFunctionForTransform;
59
66
  }
60
67
 
61
- `,
62
- avoidSourceMap
63
- );
64
- newCode = `${refreshHead}${newCode}
68
+ `, avoidSourceMap);
69
+ newCode = `${refreshHead}${newCode}
65
70
 
66
71
  if (import.meta.hot && !inWebWorker) {
67
72
  window.$RefreshReg$ = prevRefreshReg;
68
73
  window.$RefreshSig$ = prevRefreshSig;
69
74
  }
70
75
  `;
71
- if (newMap) {
72
- newMap.mappings = ";".repeat(16) + newMap.mappings;
73
- }
74
- }
75
- const sharedHead = removeLineBreaksIfNeeded(
76
- `import * as RefreshRuntime from "${reactRefreshHost}${runtimePublicPath}";
76
+ if (newMap) newMap.mappings = ";".repeat(16) + newMap.mappings;
77
+ }
78
+ const sharedHead = removeLineBreaksIfNeeded(`import * as RefreshRuntime from "${reactRefreshHost}${runtimePublicPath}";
77
79
  const inWebWorker = typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope;
78
80
 
79
- `,
80
- avoidSourceMap
81
- );
82
- newCode = `${sharedHead}${newCode}
81
+ `, avoidSourceMap);
82
+ newCode = `${sharedHead}${newCode}
83
83
 
84
84
  if (import.meta.hot && !inWebWorker) {
85
85
  RefreshRuntime.__hmr_import(import.meta.url).then((currentExports) => {
86
- RefreshRuntime.registerExportsForReactRefresh(${JSON.stringify(
87
- id
88
- )}, currentExports);
86
+ RefreshRuntime.registerExportsForReactRefresh(${JSON.stringify(id)}, currentExports);
89
87
  import.meta.hot.accept((nextExports) => {
90
88
  if (!nextExports) return;
91
- const invalidateMessage = RefreshRuntime.validateRefreshBoundaryAndEnqueueUpdate(${JSON.stringify(
92
- id
93
- )}, currentExports, nextExports);
89
+ const invalidateMessage = RefreshRuntime.validateRefreshBoundaryAndEnqueueUpdate(${JSON.stringify(id)}, currentExports, nextExports);
94
90
  if (invalidateMessage) import.meta.hot.invalidate(invalidateMessage);
95
91
  });
96
92
  });
97
93
  }
98
94
  `;
99
- if (newMap) {
100
- newMap.mappings = ";;;" + newMap.mappings;
101
- }
102
- return { code: newCode, map: newMap };
95
+ if (newMap) newMap.mappings = ";;;" + newMap.mappings;
96
+ return {
97
+ code: newCode,
98
+ map: newMap
99
+ };
103
100
  }
104
101
  function removeLineBreaksIfNeeded(code, enabled) {
105
- return enabled ? code.replace(/\n/g, "") : code;
102
+ return enabled ? code.replace(/\n/g, "") : code;
106
103
  }
107
104
 
108
- const silenceUseClientWarning = (userConfig) => ({
109
- rollupOptions: {
110
- onwarn(warning, defaultHandler) {
111
- if (warning.code === "MODULE_LEVEL_DIRECTIVE" && (warning.message.includes("use client") || warning.message.includes("use server"))) {
112
- return;
113
- }
114
- if (warning.code === "SOURCEMAP_ERROR" && warning.message.includes("resolve original location") && warning.pos === 0) {
115
- return;
116
- }
117
- if (userConfig.build?.rollupOptions?.onwarn) {
118
- userConfig.build.rollupOptions.onwarn(warning, defaultHandler);
119
- } else {
120
- defaultHandler(warning);
121
- }
122
- }
123
- }
124
- });
105
+ //#endregion
106
+ //#region ../common/warning.ts
107
+ const silenceUseClientWarning = (userConfig) => ({ rollupOptions: { onwarn(warning, defaultHandler) {
108
+ var _userConfig$build;
109
+ if (warning.code === "MODULE_LEVEL_DIRECTIVE" && (warning.message.includes("use client") || warning.message.includes("use server"))) return;
110
+ if (warning.code === "SOURCEMAP_ERROR" && warning.message.includes("resolve original location") && warning.pos === 0) return;
111
+ if ((_userConfig$build = userConfig.build) === null || _userConfig$build === void 0 || (_userConfig$build = _userConfig$build.rollupOptions) === null || _userConfig$build === void 0 ? void 0 : _userConfig$build.onwarn) userConfig.build.rollupOptions.onwarn(warning, defaultHandler);
112
+ else defaultHandler(warning);
113
+ } } });
125
114
 
126
- const _dirname = node_path.dirname(node_url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href))));
127
- const refreshRuntimePath = node_path.join(_dirname, "refresh-runtime.js") ;
115
+ //#endregion
116
+ //#region src/index.ts
117
+ const _dirname = (0, node_path.dirname)((0, node_url.fileURLToPath)(require("url").pathToFileURL(__filename).href));
118
+ const refreshRuntimePath = (0, node_path.join)(_dirname, "refresh-runtime.js");
128
119
  let babel;
129
120
  async function loadBabel() {
130
- if (!babel) {
131
- babel = await import('@babel/core');
132
- }
133
- return babel;
121
+ if (!babel) babel = await import("@babel/core");
122
+ return babel;
134
123
  }
135
124
  const defaultIncludeRE = /\.[tj]sx?$/;
136
125
  const tsRE = /\.tsx?$/;
137
126
  function viteReact(opts = {}) {
138
- const include = opts.include ?? defaultIncludeRE;
139
- const exclude = opts.exclude;
140
- const filter = vite.createFilter(include, exclude);
141
- const jsxImportSource = opts.jsxImportSource ?? "react";
142
- const jsxImportRuntime = `${jsxImportSource}/jsx-runtime`;
143
- const jsxImportDevRuntime = `${jsxImportSource}/jsx-dev-runtime`;
144
- let isProduction = true;
145
- let projectRoot = process.cwd();
146
- let skipFastRefresh = false;
147
- let runPluginOverrides;
148
- let staticBabelOptions;
149
- const importReactRE = /\bimport\s+(?:\*\s+as\s+)?React\b/;
150
- const viteBabel = {
151
- name: "vite:react-babel",
152
- enforce: "pre",
153
- config() {
154
- if (opts.jsxRuntime === "classic") {
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
- }
174
- } else {
175
- return {
176
- esbuild: {
177
- jsx: "automatic",
178
- jsxImportSource: opts.jsxImportSource
179
- },
180
- optimizeDeps: "rolldownVersion" in vite__namespace ? { rollupOptions: { jsx: { mode: "automatic" } } } : { esbuildOptions: { jsx: "automatic" } }
181
- };
182
- }
183
- },
184
- configResolved(config) {
185
- projectRoot = config.root;
186
- isProduction = config.isProduction;
187
- skipFastRefresh = isProduction || config.command === "build" || config.server.hmr === false;
188
- if ("jsxPure" in opts) {
189
- config.logger.warnOnce(
190
- "[@vitejs/plugin-react] jsxPure was removed. You can configure esbuild.jsxSideEffects directly."
191
- );
192
- }
193
- const hooks = config.plugins.map((plugin) => plugin.api?.reactBabel).filter(defined);
194
- if ("rolldownVersion" in vite__namespace && !opts.babel && !hooks.length && !opts.disableOxcRecommendation) {
195
- config.logger.warn(
196
- "[vite:react-babel] We recommend switching to `@vitejs/plugin-react-oxc` for improved performance. More information at https://vite.dev/rolldown"
197
- );
198
- }
199
- if (hooks.length > 0) {
200
- runPluginOverrides = (babelOptions, context) => {
201
- hooks.forEach((hook) => hook(babelOptions, context, config));
202
- };
203
- } else if (typeof opts.babel !== "function") {
204
- staticBabelOptions = createBabelOptions(opts.babel);
205
- if (canSkipBabel(staticBabelOptions.plugins, staticBabelOptions) && skipFastRefresh && (opts.jsxRuntime === "classic" ? isProduction : true)) {
206
- delete viteBabel.transform;
207
- }
208
- }
209
- },
210
- transform: {
211
- filter: {
212
- id: {
213
- include: pluginutils.makeIdFiltersToMatchWithQuery(include),
214
- exclude: [
215
- ...exclude ? pluginutils.makeIdFiltersToMatchWithQuery(ensureArray(exclude)) : [],
216
- /\/node_modules\//
217
- ]
218
- }
219
- },
220
- async handler(code, id, options) {
221
- if (id.includes("/node_modules/")) return;
222
- const [filepath] = id.split("?");
223
- if (!filter(filepath)) return;
224
- const ssr = options?.ssr === true;
225
- const babelOptions = (() => {
226
- if (staticBabelOptions) return staticBabelOptions;
227
- const newBabelOptions = createBabelOptions(
228
- typeof opts.babel === "function" ? opts.babel(id, { ssr }) : opts.babel
229
- );
230
- runPluginOverrides?.(newBabelOptions, { id, ssr });
231
- return newBabelOptions;
232
- })();
233
- const plugins = [...babelOptions.plugins];
234
- const isJSX = filepath.endsWith("x");
235
- const useFastRefresh = !skipFastRefresh && !ssr && (isJSX || (opts.jsxRuntime === "classic" ? importReactRE.test(code) : code.includes(jsxImportDevRuntime) || code.includes(jsxImportRuntime)));
236
- if (useFastRefresh) {
237
- plugins.push([
238
- await loadPlugin("react-refresh/babel"),
239
- { skipEnvCheck: true }
240
- ]);
241
- }
242
- if (opts.jsxRuntime === "classic" && isJSX) {
243
- if (!isProduction) {
244
- plugins.push(
245
- await loadPlugin("@babel/plugin-transform-react-jsx-self"),
246
- await loadPlugin("@babel/plugin-transform-react-jsx-source")
247
- );
248
- }
249
- }
250
- if (canSkipBabel(plugins, babelOptions)) {
251
- return;
252
- }
253
- const parserPlugins = [...babelOptions.parserOpts.plugins];
254
- if (!filepath.endsWith(".ts")) {
255
- parserPlugins.push("jsx");
256
- }
257
- if (tsRE.test(filepath)) {
258
- parserPlugins.push("typescript");
259
- }
260
- const babel2 = await loadBabel();
261
- const result = await babel2.transformAsync(code, {
262
- ...babelOptions,
263
- root: projectRoot,
264
- filename: id,
265
- sourceFileName: filepath,
266
- // Required for esbuild.jsxDev to provide correct line numbers
267
- // This creates issues the react compiler because the re-order is too important
268
- // People should use @babel/plugin-transform-react-jsx-development to get back good line numbers
269
- retainLines: getReactCompilerPlugin(plugins) != null ? false : !isProduction && isJSX && opts.jsxRuntime !== "classic",
270
- parserOpts: {
271
- ...babelOptions.parserOpts,
272
- sourceType: "module",
273
- allowAwaitOutsideFunction: true,
274
- plugins: parserPlugins
275
- },
276
- generatorOpts: {
277
- ...babelOptions.generatorOpts,
278
- // import attributes parsing available without plugin since 7.26
279
- importAttributesKeyword: "with",
280
- decoratorsBeforeExport: true
281
- },
282
- plugins,
283
- sourceMaps: true
284
- });
285
- if (result) {
286
- if (!useFastRefresh) {
287
- return { code: result.code, map: result.map };
288
- }
289
- return addRefreshWrapper(
290
- result.code,
291
- result.map,
292
- "@vitejs/plugin-react",
293
- id,
294
- opts.reactRefreshHost
295
- );
296
- }
297
- }
298
- }
299
- };
300
- const dependencies = [
301
- "react",
302
- "react-dom",
303
- jsxImportDevRuntime,
304
- jsxImportRuntime
305
- ];
306
- const staticBabelPlugins = typeof opts.babel === "object" ? opts.babel?.plugins ?? [] : [];
307
- const reactCompilerPlugin = getReactCompilerPlugin(staticBabelPlugins);
308
- if (reactCompilerPlugin != null) {
309
- const reactCompilerRuntimeModule = getReactCompilerRuntimeModule(reactCompilerPlugin);
310
- dependencies.push(reactCompilerRuntimeModule);
311
- }
312
- const viteReactRefresh = {
313
- name: "vite:react-refresh",
314
- enforce: "pre",
315
- config: (userConfig) => ({
316
- build: silenceUseClientWarning(userConfig),
317
- optimizeDeps: {
318
- include: dependencies
319
- },
320
- resolve: {
321
- dedupe: ["react", "react-dom"]
322
- }
323
- }),
324
- resolveId: {
325
- filter: { id: pluginutils.exactRegex(runtimePublicPath) },
326
- handler(id) {
327
- if (id === runtimePublicPath) {
328
- return id;
329
- }
330
- }
331
- },
332
- load: {
333
- filter: { id: pluginutils.exactRegex(runtimePublicPath) },
334
- handler(id) {
335
- if (id === runtimePublicPath) {
336
- return node_fs.readFileSync(refreshRuntimePath, "utf-8").replace(
337
- /__README_URL__/g,
338
- "https://github.com/vitejs/vite-plugin-react/tree/main/packages/plugin-react"
339
- );
340
- }
341
- }
342
- },
343
- transformIndexHtml(_, config) {
344
- if (!skipFastRefresh)
345
- return [
346
- {
347
- tag: "script",
348
- attrs: { type: "module" },
349
- children: getPreambleCode(config.server.config.base)
350
- }
351
- ];
352
- }
353
- };
354
- return [viteBabel, viteReactRefresh];
127
+ var _opts$babel;
128
+ const include = opts.include ?? defaultIncludeRE;
129
+ const exclude = opts.exclude;
130
+ const filter = (0, vite.createFilter)(include, exclude);
131
+ const jsxImportSource = opts.jsxImportSource ?? "react";
132
+ const jsxImportRuntime = `${jsxImportSource}/jsx-runtime`;
133
+ const jsxImportDevRuntime = `${jsxImportSource}/jsx-dev-runtime`;
134
+ let runningInVite = false;
135
+ let isProduction = true;
136
+ let projectRoot = process.cwd();
137
+ let skipFastRefresh = true;
138
+ let runPluginOverrides;
139
+ let staticBabelOptions;
140
+ const importReactRE = /\bimport\s+(?:\*\s+as\s+)?React\b/;
141
+ const viteBabel = {
142
+ name: "vite:react-babel",
143
+ enforce: "pre",
144
+ config() {
145
+ if (opts.jsxRuntime === "classic") if ("rolldownVersion" in vite) return { oxc: { jsx: {
146
+ runtime: "classic",
147
+ development: false
148
+ } } };
149
+ else return { esbuild: { jsx: "transform" } };
150
+ else return {
151
+ esbuild: {
152
+ jsx: "automatic",
153
+ jsxImportSource: opts.jsxImportSource
154
+ },
155
+ optimizeDeps: "rolldownVersion" in vite ? { rollupOptions: { jsx: { mode: "automatic" } } } : { esbuildOptions: { jsx: "automatic" } }
156
+ };
157
+ },
158
+ configResolved(config) {
159
+ runningInVite = true;
160
+ projectRoot = config.root;
161
+ isProduction = config.isProduction;
162
+ skipFastRefresh = isProduction || config.command === "build" || config.server.hmr === false;
163
+ if ("jsxPure" in opts) config.logger.warnOnce("[@vitejs/plugin-react] jsxPure was removed. You can configure esbuild.jsxSideEffects directly.");
164
+ const hooks = config.plugins.map((plugin) => {
165
+ var _plugin$api;
166
+ return (_plugin$api = plugin.api) === null || _plugin$api === void 0 ? void 0 : _plugin$api.reactBabel;
167
+ }).filter(defined);
168
+ if ("rolldownVersion" in vite && !opts.babel && !hooks.length && !opts.disableOxcRecommendation) config.logger.warn("[vite:react-babel] We recommend switching to `@vitejs/plugin-react-oxc` for improved performance. More information at https://vite.dev/rolldown");
169
+ if (hooks.length > 0) runPluginOverrides = (babelOptions, context) => {
170
+ hooks.forEach((hook) => hook(babelOptions, context, config));
171
+ };
172
+ else if (typeof opts.babel !== "function") {
173
+ staticBabelOptions = createBabelOptions(opts.babel);
174
+ if (canSkipBabel(staticBabelOptions.plugins, staticBabelOptions) && skipFastRefresh && (opts.jsxRuntime === "classic" ? isProduction : true)) delete viteBabel.transform;
175
+ }
176
+ },
177
+ options(options) {
178
+ if (!runningInVite) {
179
+ options.jsx = {
180
+ mode: opts.jsxRuntime,
181
+ importSource: opts.jsxImportSource
182
+ };
183
+ return options;
184
+ }
185
+ },
186
+ transform: {
187
+ filter: { id: {
188
+ include: (0, __rolldown_pluginutils.makeIdFiltersToMatchWithQuery)(include),
189
+ exclude: [...exclude ? (0, __rolldown_pluginutils.makeIdFiltersToMatchWithQuery)(ensureArray(exclude)) : [], /\/node_modules\//]
190
+ } },
191
+ async handler(code, id, options) {
192
+ if (id.includes("/node_modules/")) return;
193
+ const [filepath] = id.split("?");
194
+ if (!filter(filepath)) return;
195
+ const ssr = (options === null || options === void 0 ? void 0 : options.ssr) === true;
196
+ const babelOptions = (() => {
197
+ if (staticBabelOptions) return staticBabelOptions;
198
+ const newBabelOptions = createBabelOptions(typeof opts.babel === "function" ? opts.babel(id, { ssr }) : opts.babel);
199
+ runPluginOverrides === null || runPluginOverrides === void 0 || runPluginOverrides(newBabelOptions, {
200
+ id,
201
+ ssr
202
+ });
203
+ return newBabelOptions;
204
+ })();
205
+ const plugins = [...babelOptions.plugins];
206
+ const isJSX = filepath.endsWith("x");
207
+ const useFastRefresh = !skipFastRefresh && !ssr && (isJSX || (opts.jsxRuntime === "classic" ? importReactRE.test(code) : code.includes(jsxImportDevRuntime) || code.includes(jsxImportRuntime)));
208
+ if (useFastRefresh) plugins.push([await loadPlugin("react-refresh/babel"), { skipEnvCheck: true }]);
209
+ if (opts.jsxRuntime === "classic" && isJSX) {
210
+ if (!isProduction) plugins.push(await loadPlugin("@babel/plugin-transform-react-jsx-self"), await loadPlugin("@babel/plugin-transform-react-jsx-source"));
211
+ }
212
+ if (canSkipBabel(plugins, babelOptions)) return;
213
+ const parserPlugins = [...babelOptions.parserOpts.plugins];
214
+ if (!filepath.endsWith(".ts")) parserPlugins.push("jsx");
215
+ if (tsRE.test(filepath)) parserPlugins.push("typescript");
216
+ const babel$1 = await loadBabel();
217
+ const result = await babel$1.transformAsync(code, {
218
+ ...babelOptions,
219
+ root: projectRoot,
220
+ filename: id,
221
+ sourceFileName: filepath,
222
+ retainLines: getReactCompilerPlugin(plugins) != null ? false : !isProduction && isJSX && opts.jsxRuntime !== "classic",
223
+ parserOpts: {
224
+ ...babelOptions.parserOpts,
225
+ sourceType: "module",
226
+ allowAwaitOutsideFunction: true,
227
+ plugins: parserPlugins
228
+ },
229
+ generatorOpts: {
230
+ ...babelOptions.generatorOpts,
231
+ importAttributesKeyword: "with",
232
+ decoratorsBeforeExport: true
233
+ },
234
+ plugins,
235
+ sourceMaps: true
236
+ });
237
+ if (result) {
238
+ if (!useFastRefresh) return {
239
+ code: result.code,
240
+ map: result.map
241
+ };
242
+ return addRefreshWrapper(result.code, result.map, "@vitejs/plugin-react", id, opts.reactRefreshHost);
243
+ }
244
+ }
245
+ }
246
+ };
247
+ const dependencies = [
248
+ "react",
249
+ "react-dom",
250
+ jsxImportDevRuntime,
251
+ jsxImportRuntime
252
+ ];
253
+ const staticBabelPlugins = typeof opts.babel === "object" ? ((_opts$babel = opts.babel) === null || _opts$babel === void 0 ? void 0 : _opts$babel.plugins) ?? [] : [];
254
+ const reactCompilerPlugin = getReactCompilerPlugin(staticBabelPlugins);
255
+ if (reactCompilerPlugin != null) {
256
+ const reactCompilerRuntimeModule = getReactCompilerRuntimeModule(reactCompilerPlugin);
257
+ dependencies.push(reactCompilerRuntimeModule);
258
+ }
259
+ const viteReactRefresh = {
260
+ name: "vite:react-refresh",
261
+ enforce: "pre",
262
+ config: (userConfig) => ({
263
+ build: silenceUseClientWarning(userConfig),
264
+ optimizeDeps: { include: dependencies },
265
+ resolve: { dedupe: ["react", "react-dom"] }
266
+ }),
267
+ resolveId: {
268
+ filter: { id: (0, __rolldown_pluginutils.exactRegex)(runtimePublicPath) },
269
+ handler(id) {
270
+ if (id === runtimePublicPath) return id;
271
+ }
272
+ },
273
+ load: {
274
+ filter: { id: (0, __rolldown_pluginutils.exactRegex)(runtimePublicPath) },
275
+ handler(id) {
276
+ if (id === runtimePublicPath) return (0, node_fs.readFileSync)(refreshRuntimePath, "utf-8").replace(/__README_URL__/g, "https://github.com/vitejs/vite-plugin-react/tree/main/packages/plugin-react");
277
+ }
278
+ },
279
+ transformIndexHtml(_, config) {
280
+ if (!skipFastRefresh) return [{
281
+ tag: "script",
282
+ attrs: { type: "module" },
283
+ children: getPreambleCode(config.server.config.base)
284
+ }];
285
+ }
286
+ };
287
+ return [viteBabel, viteReactRefresh];
355
288
  }
356
289
  viteReact.preambleCode = preambleCode;
357
290
  function canSkipBabel(plugins, babelOptions) {
358
- return !(plugins.length || babelOptions.presets.length || babelOptions.configFile || babelOptions.babelrc);
291
+ return !(plugins.length || babelOptions.presets.length || babelOptions.configFile || babelOptions.babelrc);
359
292
  }
360
293
  const loadedPlugin = /* @__PURE__ */ new Map();
361
294
  function loadPlugin(path) {
362
- const cached = loadedPlugin.get(path);
363
- if (cached) return cached;
364
- const promise = import(path).then((module) => {
365
- const value = module.default || module;
366
- loadedPlugin.set(path, value);
367
- return value;
368
- });
369
- loadedPlugin.set(path, promise);
370
- return promise;
295
+ const cached = loadedPlugin.get(path);
296
+ if (cached) return cached;
297
+ const promise = import(path).then((module$1) => {
298
+ const value = module$1.default || module$1;
299
+ loadedPlugin.set(path, value);
300
+ return value;
301
+ });
302
+ loadedPlugin.set(path, promise);
303
+ return promise;
371
304
  }
372
305
  function createBabelOptions(rawOptions) {
373
- const babelOptions = {
374
- babelrc: false,
375
- configFile: false,
376
- ...rawOptions
377
- };
378
- babelOptions.plugins ||= [];
379
- babelOptions.presets ||= [];
380
- babelOptions.overrides ||= [];
381
- babelOptions.parserOpts ||= {};
382
- babelOptions.parserOpts.plugins ||= [];
383
- return babelOptions;
306
+ var _babelOptions$parserO;
307
+ const babelOptions = {
308
+ babelrc: false,
309
+ configFile: false,
310
+ ...rawOptions
311
+ };
312
+ babelOptions.plugins || (babelOptions.plugins = []);
313
+ babelOptions.presets || (babelOptions.presets = []);
314
+ babelOptions.overrides || (babelOptions.overrides = []);
315
+ babelOptions.parserOpts || (babelOptions.parserOpts = {});
316
+ (_babelOptions$parserO = babelOptions.parserOpts).plugins || (_babelOptions$parserO.plugins = []);
317
+ return babelOptions;
384
318
  }
385
319
  function defined(value) {
386
- return value !== void 0;
320
+ return value !== void 0;
387
321
  }
388
322
  function getReactCompilerPlugin(plugins) {
389
- return plugins.find(
390
- (p) => p === "babel-plugin-react-compiler" || Array.isArray(p) && p[0] === "babel-plugin-react-compiler"
391
- );
323
+ return plugins.find((p) => p === "babel-plugin-react-compiler" || Array.isArray(p) && p[0] === "babel-plugin-react-compiler");
392
324
  }
393
325
  function getReactCompilerRuntimeModule(plugin) {
394
- let moduleName = "react/compiler-runtime";
395
- if (Array.isArray(plugin)) {
396
- if (plugin[1]?.target === "17" || plugin[1]?.target === "18") {
397
- moduleName = "react-compiler-runtime";
398
- } else if (typeof plugin[1]?.runtimeModule === "string") {
399
- moduleName = plugin[1]?.runtimeModule;
400
- }
401
- }
402
- return moduleName;
326
+ let moduleName = "react/compiler-runtime";
327
+ if (Array.isArray(plugin)) {
328
+ var _plugin$, _plugin$2, _plugin$3;
329
+ if (((_plugin$ = plugin[1]) === null || _plugin$ === void 0 ? void 0 : _plugin$.target) === "17" || ((_plugin$2 = plugin[1]) === null || _plugin$2 === void 0 ? void 0 : _plugin$2.target) === "18") moduleName = "react-compiler-runtime";
330
+ else if (typeof ((_plugin$3 = plugin[1]) === null || _plugin$3 === void 0 ? void 0 : _plugin$3.runtimeModule) === "string") {
331
+ var _plugin$4;
332
+ moduleName = (_plugin$4 = plugin[1]) === null || _plugin$4 === void 0 ? void 0 : _plugin$4.runtimeModule;
333
+ }
334
+ }
335
+ return moduleName;
403
336
  }
404
337
  function ensureArray(value) {
405
- return Array.isArray(value) ? value : [value];
338
+ return Array.isArray(value) ? value : [value];
406
339
  }
407
340
 
341
+ //#endregion
408
342
  module.exports = viteReact;
409
- module.exports.default = viteReact;
343
+ module.exports.default = module.exports