@vitejs/plugin-react 5.0.2 → 5.0.3
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.js +22 -55
- package/dist/refresh-runtime.js +1 -8
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -14,22 +14,15 @@ injectIntoGlobalHook(window);
|
|
|
14
14
|
window.$RefreshReg$ = () => {};
|
|
15
15
|
window.$RefreshSig$ = () => (type) => type;`;
|
|
16
16
|
const getPreambleCode = (base) => preambleCode.replace("__BASE__", base);
|
|
17
|
-
|
|
18
|
-
function addRefreshWrapper(code, map, pluginName, id, reactRefreshHost = "") {
|
|
17
|
+
function addRefreshWrapper(code, pluginName, id, reactRefreshHost = "") {
|
|
19
18
|
const hasRefresh = refreshContentRE.test(code);
|
|
20
19
|
const onlyReactComp = !hasRefresh && reactCompRE.test(code);
|
|
21
|
-
|
|
22
|
-
if (!hasRefresh && !onlyReactComp) return {
|
|
23
|
-
code,
|
|
24
|
-
map: normalizedMap
|
|
25
|
-
};
|
|
26
|
-
const avoidSourceMap = map === avoidSourceMapOption;
|
|
27
|
-
const newMap = typeof normalizedMap === "string" ? JSON.parse(normalizedMap) : normalizedMap;
|
|
20
|
+
if (!hasRefresh && !onlyReactComp) return void 0;
|
|
28
21
|
let newCode = code;
|
|
29
|
-
|
|
30
|
-
const refreshHead = removeLineBreaksIfNeeded(`let prevRefreshReg;
|
|
31
|
-
let prevRefreshSig;
|
|
22
|
+
newCode += `
|
|
32
23
|
|
|
24
|
+
import * as RefreshRuntime from "${reactRefreshHost}${runtimePublicPath}";
|
|
25
|
+
const inWebWorker = typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope;
|
|
33
26
|
if (import.meta.hot && !inWebWorker) {
|
|
34
27
|
if (!window.$RefreshReg$) {
|
|
35
28
|
throw new Error(
|
|
@@ -37,29 +30,6 @@ if (import.meta.hot && !inWebWorker) {
|
|
|
37
30
|
);
|
|
38
31
|
}
|
|
39
32
|
|
|
40
|
-
prevRefreshReg = window.$RefreshReg$;
|
|
41
|
-
prevRefreshSig = window.$RefreshSig$;
|
|
42
|
-
window.$RefreshReg$ = RefreshRuntime.getRefreshReg(${JSON.stringify(id)});
|
|
43
|
-
window.$RefreshSig$ = RefreshRuntime.createSignatureFunctionForTransform;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
`, avoidSourceMap);
|
|
47
|
-
newCode = `${refreshHead}${newCode}
|
|
48
|
-
|
|
49
|
-
if (import.meta.hot && !inWebWorker) {
|
|
50
|
-
window.$RefreshReg$ = prevRefreshReg;
|
|
51
|
-
window.$RefreshSig$ = prevRefreshSig;
|
|
52
|
-
}
|
|
53
|
-
`;
|
|
54
|
-
if (newMap) newMap.mappings = ";".repeat(16) + newMap.mappings;
|
|
55
|
-
}
|
|
56
|
-
const sharedHead = removeLineBreaksIfNeeded(`import * as RefreshRuntime from "${reactRefreshHost}${runtimePublicPath}";
|
|
57
|
-
const inWebWorker = typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope;
|
|
58
|
-
|
|
59
|
-
`, avoidSourceMap);
|
|
60
|
-
newCode = `${sharedHead}${newCode}
|
|
61
|
-
|
|
62
|
-
if (import.meta.hot && !inWebWorker) {
|
|
63
33
|
RefreshRuntime.__hmr_import(import.meta.url).then((currentExports) => {
|
|
64
34
|
RefreshRuntime.registerExportsForReactRefresh(${JSON.stringify(id)}, currentExports);
|
|
65
35
|
import.meta.hot.accept((nextExports) => {
|
|
@@ -70,14 +40,10 @@ if (import.meta.hot && !inWebWorker) {
|
|
|
70
40
|
});
|
|
71
41
|
}
|
|
72
42
|
`;
|
|
73
|
-
if (
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
function removeLineBreaksIfNeeded(code, enabled) {
|
|
80
|
-
return enabled ? code.replace(/\n/g, "") : code;
|
|
43
|
+
if (hasRefresh) newCode += `function $RefreshReg$(type, id) { return RefreshRuntime.register(type, ${JSON.stringify(id)} + ' ' + id) }
|
|
44
|
+
function $RefreshSig$() { return RefreshRuntime.createSignatureFunctionForTransform(); }
|
|
45
|
+
`;
|
|
46
|
+
return newCode;
|
|
81
47
|
}
|
|
82
48
|
|
|
83
49
|
//#endregion
|
|
@@ -127,8 +93,8 @@ function viteReact(opts = {}) {
|
|
|
127
93
|
refresh: command === "serve",
|
|
128
94
|
development: false
|
|
129
95
|
},
|
|
130
|
-
jsxRefreshInclude: include,
|
|
131
|
-
jsxRefreshExclude: exclude
|
|
96
|
+
jsxRefreshInclude: makeIdFiltersToMatchWithQuery(include),
|
|
97
|
+
jsxRefreshExclude: makeIdFiltersToMatchWithQuery(exclude)
|
|
132
98
|
} };
|
|
133
99
|
else return {
|
|
134
100
|
oxc: {
|
|
@@ -137,8 +103,8 @@ function viteReact(opts = {}) {
|
|
|
137
103
|
importSource: opts.jsxImportSource,
|
|
138
104
|
refresh: command === "serve"
|
|
139
105
|
},
|
|
140
|
-
jsxRefreshInclude: include,
|
|
141
|
-
jsxRefreshExclude: exclude
|
|
106
|
+
jsxRefreshInclude: makeIdFiltersToMatchWithQuery(include),
|
|
107
|
+
jsxRefreshExclude: makeIdFiltersToMatchWithQuery(exclude)
|
|
142
108
|
},
|
|
143
109
|
optimizeDeps: { rollupOptions: { transform: { jsx: { runtime: "automatic" } } } }
|
|
144
110
|
};
|
|
@@ -212,8 +178,7 @@ function viteReact(opts = {}) {
|
|
|
212
178
|
const parserPlugins = [...babelOptions.parserOpts.plugins];
|
|
213
179
|
if (!filepath.endsWith(".ts")) parserPlugins.push("jsx");
|
|
214
180
|
if (tsRE.test(filepath)) parserPlugins.push("typescript");
|
|
215
|
-
const
|
|
216
|
-
const result = await babel$1.transformAsync(code, {
|
|
181
|
+
const result = await (await loadBabel()).transformAsync(code, {
|
|
217
182
|
...babelOptions,
|
|
218
183
|
root: projectRoot,
|
|
219
184
|
filename: id,
|
|
@@ -238,7 +203,10 @@ function viteReact(opts = {}) {
|
|
|
238
203
|
code: result.code,
|
|
239
204
|
map: result.map
|
|
240
205
|
};
|
|
241
|
-
return
|
|
206
|
+
return {
|
|
207
|
+
code: addRefreshWrapper(result.code, "@vitejs/plugin-react", id, opts.reactRefreshHost) ?? result.code,
|
|
208
|
+
map: result.map
|
|
209
|
+
};
|
|
242
210
|
}
|
|
243
211
|
}
|
|
244
212
|
}
|
|
@@ -255,13 +223,12 @@ function viteReact(opts = {}) {
|
|
|
255
223
|
const ssr = options?.ssr === true;
|
|
256
224
|
const [filepath] = id.split("?");
|
|
257
225
|
const isJSX = filepath.endsWith("x");
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
return {
|
|
226
|
+
if (!(!skipFastRefresh && !ssr && (isJSX || code.includes(jsxImportDevRuntime) || code.includes(jsxImportRuntime)))) return;
|
|
227
|
+
const newCode = addRefreshWrapper(code, "@vitejs/plugin-react", id, opts.reactRefreshHost);
|
|
228
|
+
return newCode ? {
|
|
262
229
|
code: newCode,
|
|
263
230
|
map: null
|
|
264
|
-
};
|
|
231
|
+
} : void 0;
|
|
265
232
|
}
|
|
266
233
|
}
|
|
267
234
|
};
|
package/dist/refresh-runtime.js
CHANGED
|
@@ -243,7 +243,7 @@ function performReactRefresh() {
|
|
|
243
243
|
}
|
|
244
244
|
}
|
|
245
245
|
|
|
246
|
-
function register(type, id) {
|
|
246
|
+
export function register(type, id) {
|
|
247
247
|
if (type === null) {
|
|
248
248
|
return
|
|
249
249
|
}
|
|
@@ -564,10 +564,6 @@ function isPlainObject(obj) {
|
|
|
564
564
|
* Plugin utils
|
|
565
565
|
*/
|
|
566
566
|
|
|
567
|
-
export function getRefreshReg(filename) {
|
|
568
|
-
return (type, id) => register(type, filename + ' ' + id)
|
|
569
|
-
}
|
|
570
|
-
|
|
571
567
|
// Taken from https://github.com/pmmmwh/react-refresh-webpack-plugin/blob/main/lib/runtime/RefreshUtils.js#L141
|
|
572
568
|
// This allows to resister components not detected by SWC like styled component
|
|
573
569
|
export function registerExportsForReactRefresh(filename, moduleExports) {
|
|
@@ -653,10 +649,7 @@ export function validateRefreshBoundaryAndEnqueueUpdate(
|
|
|
653
649
|
|
|
654
650
|
function predicateOnExport(ignoredExports, moduleExports, predicate) {
|
|
655
651
|
for (const key in moduleExports) {
|
|
656
|
-
if (key === '__esModule') continue
|
|
657
652
|
if (ignoredExports.includes(key)) continue
|
|
658
|
-
const desc = Object.getOwnPropertyDescriptor(moduleExports, key)
|
|
659
|
-
if (desc && desc.get) return key
|
|
660
653
|
if (!predicate(key, moduleExports[key])) return key
|
|
661
654
|
}
|
|
662
655
|
return true
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vitejs/plugin-react",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.3",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Evan You",
|
|
6
6
|
"description": "The default Vite plugin for React projects",
|
|
@@ -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.
|
|
43
|
+
"@babel/core": "^7.28.4",
|
|
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.
|
|
46
|
+
"@rolldown/pluginutils": "1.0.0-beta.35",
|
|
47
47
|
"@types/babel__core": "^7.20.5",
|
|
48
48
|
"react-refresh": "^0.17.0"
|
|
49
49
|
},
|
|
@@ -52,10 +52,10 @@
|
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
54
|
"@vitejs/react-common": "workspace:*",
|
|
55
|
-
"babel-plugin-react-compiler": "19.1.0-rc.
|
|
55
|
+
"babel-plugin-react-compiler": "19.1.0-rc.3",
|
|
56
56
|
"react": "^19.1.1",
|
|
57
57
|
"react-dom": "^19.1.1",
|
|
58
|
-
"rolldown": "1.0.0-beta.
|
|
58
|
+
"rolldown": "1.0.0-beta.35",
|
|
59
59
|
"tsdown": "^0.14.2",
|
|
60
60
|
"vitest": "^3.2.4"
|
|
61
61
|
}
|