@vitejs/plugin-react 4.6.0 → 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 +269 -346
- package/dist/index.d.cts +50 -50
- package/dist/index.d.ts +50 -50
- package/dist/index.js +320 -0
- package/dist/refresh-runtime.js +23 -0
- package/package.json +11 -12
- package/dist/index.d.mts +0 -67
- package/dist/index.mjs +0 -403
package/dist/index.cjs
CHANGED
@@ -1,48 +1,55 @@
|
|
1
|
-
|
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
|
-
|
4
|
-
const
|
5
|
-
const
|
6
|
-
const
|
7
|
-
const
|
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
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
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,363 +65,279 @@ if (import.meta.hot && !inWebWorker) {
|
|
58
65
|
window.$RefreshSig$ = RefreshRuntime.createSignatureFunctionForTransform;
|
59
66
|
}
|
60
67
|
|
61
|
-
`,
|
62
|
-
|
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
|
-
|
72
|
-
|
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
|
-
|
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
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
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
|
-
|
102
|
+
return enabled ? code.replace(/\n/g, "") : code;
|
106
103
|
}
|
107
104
|
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
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
|
-
|
127
|
-
|
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
|
-
|
131
|
-
|
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
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
}
|
300
|
-
return addRefreshWrapper(
|
301
|
-
result.code,
|
302
|
-
result.map,
|
303
|
-
"@vitejs/plugin-react",
|
304
|
-
id,
|
305
|
-
opts.reactRefreshHost
|
306
|
-
);
|
307
|
-
}
|
308
|
-
}
|
309
|
-
}
|
310
|
-
};
|
311
|
-
const dependencies = [
|
312
|
-
"react",
|
313
|
-
"react-dom",
|
314
|
-
jsxImportDevRuntime,
|
315
|
-
jsxImportRuntime
|
316
|
-
];
|
317
|
-
const staticBabelPlugins = typeof opts.babel === "object" ? opts.babel?.plugins ?? [] : [];
|
318
|
-
const reactCompilerPlugin = getReactCompilerPlugin(staticBabelPlugins);
|
319
|
-
if (reactCompilerPlugin != null) {
|
320
|
-
const reactCompilerRuntimeModule = getReactCompilerRuntimeModule(reactCompilerPlugin);
|
321
|
-
dependencies.push(reactCompilerRuntimeModule);
|
322
|
-
}
|
323
|
-
const viteReactRefresh = {
|
324
|
-
name: "vite:react-refresh",
|
325
|
-
enforce: "pre",
|
326
|
-
config: (userConfig) => ({
|
327
|
-
build: silenceUseClientWarning(userConfig),
|
328
|
-
optimizeDeps: {
|
329
|
-
include: dependencies
|
330
|
-
},
|
331
|
-
resolve: {
|
332
|
-
dedupe: ["react", "react-dom"]
|
333
|
-
}
|
334
|
-
}),
|
335
|
-
resolveId: {
|
336
|
-
filter: { id: pluginutils.exactRegex(runtimePublicPath) },
|
337
|
-
handler(id) {
|
338
|
-
if (id === runtimePublicPath) {
|
339
|
-
return id;
|
340
|
-
}
|
341
|
-
}
|
342
|
-
},
|
343
|
-
load: {
|
344
|
-
filter: { id: pluginutils.exactRegex(runtimePublicPath) },
|
345
|
-
handler(id) {
|
346
|
-
if (id === runtimePublicPath) {
|
347
|
-
return node_fs.readFileSync(refreshRuntimePath, "utf-8").replace(
|
348
|
-
/__README_URL__/g,
|
349
|
-
"https://github.com/vitejs/vite-plugin-react/tree/main/packages/plugin-react"
|
350
|
-
);
|
351
|
-
}
|
352
|
-
}
|
353
|
-
},
|
354
|
-
transformIndexHtml(_, config) {
|
355
|
-
if (!skipFastRefresh)
|
356
|
-
return [
|
357
|
-
{
|
358
|
-
tag: "script",
|
359
|
-
attrs: { type: "module" },
|
360
|
-
children: getPreambleCode(config.server.config.base)
|
361
|
-
}
|
362
|
-
];
|
363
|
-
}
|
364
|
-
};
|
365
|
-
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];
|
366
288
|
}
|
367
289
|
viteReact.preambleCode = preambleCode;
|
368
290
|
function canSkipBabel(plugins, babelOptions) {
|
369
|
-
|
291
|
+
return !(plugins.length || babelOptions.presets.length || babelOptions.configFile || babelOptions.babelrc);
|
370
292
|
}
|
371
293
|
const loadedPlugin = /* @__PURE__ */ new Map();
|
372
294
|
function loadPlugin(path) {
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
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;
|
382
304
|
}
|
383
305
|
function createBabelOptions(rawOptions) {
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
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;
|
395
318
|
}
|
396
319
|
function defined(value) {
|
397
|
-
|
320
|
+
return value !== void 0;
|
398
321
|
}
|
399
322
|
function getReactCompilerPlugin(plugins) {
|
400
|
-
|
401
|
-
(p) => p === "babel-plugin-react-compiler" || Array.isArray(p) && p[0] === "babel-plugin-react-compiler"
|
402
|
-
);
|
323
|
+
return plugins.find((p) => p === "babel-plugin-react-compiler" || Array.isArray(p) && p[0] === "babel-plugin-react-compiler");
|
403
324
|
}
|
404
325
|
function getReactCompilerRuntimeModule(plugin) {
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
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;
|
414
336
|
}
|
415
337
|
function ensureArray(value) {
|
416
|
-
|
338
|
+
return Array.isArray(value) ? value : [value];
|
417
339
|
}
|
418
340
|
|
341
|
+
//#endregion
|
419
342
|
module.exports = viteReact;
|
420
|
-
module.exports.default =
|
343
|
+
module.exports.default = module.exports
|