@vitejs/plugin-react 3.0.0-beta.0 → 3.0.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.
- package/dist/index.cjs +12 -44
- package/dist/index.mjs +12 -44
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
@@ -78,13 +78,6 @@ const timeout = `
|
|
78
78
|
}, 30);
|
79
79
|
}
|
80
80
|
`;
|
81
|
-
const footer = `
|
82
|
-
if (import.meta.hot) {
|
83
|
-
window.$RefreshReg$ = prevRefreshReg;
|
84
|
-
window.$RefreshSig$ = prevRefreshSig;
|
85
|
-
|
86
|
-
__ACCEPT__
|
87
|
-
}`;
|
88
81
|
const checkAndAccept = `
|
89
82
|
function isReactRefreshBoundary(mod) {
|
90
83
|
if (mod == null || typeof mod !== 'object') {
|
@@ -111,6 +104,7 @@ function isReactRefreshBoundary(mod) {
|
|
111
104
|
}
|
112
105
|
|
113
106
|
import.meta.hot.accept(mod => {
|
107
|
+
if (!mod) return;
|
114
108
|
if (isReactRefreshBoundary(mod)) {
|
115
109
|
${timeout}
|
116
110
|
} else {
|
@@ -118,37 +112,15 @@ import.meta.hot.accept(mod => {
|
|
118
112
|
}
|
119
113
|
});
|
120
114
|
`;
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
if (declaration) {
|
131
|
-
if (declaration.type === "ClassDeclaration")
|
132
|
-
return false;
|
133
|
-
if (declaration.type === "VariableDeclaration") {
|
134
|
-
return declaration.declarations.every(
|
135
|
-
(variable) => isComponentLikeIdentifier(variable.id)
|
136
|
-
);
|
137
|
-
}
|
138
|
-
if (declaration.type === "FunctionDeclaration") {
|
139
|
-
return !!declaration.id && isComponentLikeIdentifier(declaration.id);
|
140
|
-
}
|
141
|
-
}
|
142
|
-
return specifiers.every((spec) => {
|
143
|
-
return isComponentLikeIdentifier(spec.exported);
|
144
|
-
});
|
145
|
-
});
|
146
|
-
}
|
147
|
-
function isComponentLikeIdentifier(node) {
|
148
|
-
return node.type === "Identifier" && isComponentLikeName(node.name);
|
149
|
-
}
|
150
|
-
function isComponentLikeName(name) {
|
151
|
-
return typeof name === "string" && name[0] >= "A" && name[0] <= "Z";
|
115
|
+
const footer = `
|
116
|
+
if (import.meta.hot) {
|
117
|
+
window.$RefreshReg$ = prevRefreshReg;
|
118
|
+
window.$RefreshSig$ = prevRefreshSig;
|
119
|
+
|
120
|
+
${checkAndAccept}
|
121
|
+
}`;
|
122
|
+
function addRefreshWrapper(code, id) {
|
123
|
+
return header.replace("__SOURCE__", JSON.stringify(id)) + code + footer;
|
152
124
|
}
|
153
125
|
|
154
126
|
const prependReactImportCode = "import React from 'react'; ";
|
@@ -309,11 +281,8 @@ function viteReact(opts = {}) {
|
|
309
281
|
if (/\.tsx?$/.test(extension)) {
|
310
282
|
parserPlugins.push("typescript");
|
311
283
|
}
|
312
|
-
const
|
313
|
-
const isReasonReact = extension.endsWith(".bs.js");
|
314
|
-
const result = await transformAsync({
|
284
|
+
const result = await babel__namespace.transformAsync(code, {
|
315
285
|
...babelOptions,
|
316
|
-
ast: !isReasonReact,
|
317
286
|
root: projectRoot,
|
318
287
|
filename: id,
|
319
288
|
sourceFileName: filepath,
|
@@ -334,8 +303,7 @@ function viteReact(opts = {}) {
|
|
334
303
|
if (result) {
|
335
304
|
let code2 = result.code;
|
336
305
|
if (useFastRefresh && /\$RefreshReg\$\(/.test(code2)) {
|
337
|
-
|
338
|
-
code2 = addRefreshWrapper(code2, id, accept);
|
306
|
+
code2 = addRefreshWrapper(code2, id);
|
339
307
|
}
|
340
308
|
return {
|
341
309
|
code: code2,
|
package/dist/index.mjs
CHANGED
@@ -63,13 +63,6 @@ const timeout = `
|
|
63
63
|
}, 30);
|
64
64
|
}
|
65
65
|
`;
|
66
|
-
const footer = `
|
67
|
-
if (import.meta.hot) {
|
68
|
-
window.$RefreshReg$ = prevRefreshReg;
|
69
|
-
window.$RefreshSig$ = prevRefreshSig;
|
70
|
-
|
71
|
-
__ACCEPT__
|
72
|
-
}`;
|
73
66
|
const checkAndAccept = `
|
74
67
|
function isReactRefreshBoundary(mod) {
|
75
68
|
if (mod == null || typeof mod !== 'object') {
|
@@ -96,6 +89,7 @@ function isReactRefreshBoundary(mod) {
|
|
96
89
|
}
|
97
90
|
|
98
91
|
import.meta.hot.accept(mod => {
|
92
|
+
if (!mod) return;
|
99
93
|
if (isReactRefreshBoundary(mod)) {
|
100
94
|
${timeout}
|
101
95
|
} else {
|
@@ -103,37 +97,15 @@ import.meta.hot.accept(mod => {
|
|
103
97
|
}
|
104
98
|
});
|
105
99
|
`;
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
if (declaration) {
|
116
|
-
if (declaration.type === "ClassDeclaration")
|
117
|
-
return false;
|
118
|
-
if (declaration.type === "VariableDeclaration") {
|
119
|
-
return declaration.declarations.every(
|
120
|
-
(variable) => isComponentLikeIdentifier(variable.id)
|
121
|
-
);
|
122
|
-
}
|
123
|
-
if (declaration.type === "FunctionDeclaration") {
|
124
|
-
return !!declaration.id && isComponentLikeIdentifier(declaration.id);
|
125
|
-
}
|
126
|
-
}
|
127
|
-
return specifiers.every((spec) => {
|
128
|
-
return isComponentLikeIdentifier(spec.exported);
|
129
|
-
});
|
130
|
-
});
|
131
|
-
}
|
132
|
-
function isComponentLikeIdentifier(node) {
|
133
|
-
return node.type === "Identifier" && isComponentLikeName(node.name);
|
134
|
-
}
|
135
|
-
function isComponentLikeName(name) {
|
136
|
-
return typeof name === "string" && name[0] >= "A" && name[0] <= "Z";
|
100
|
+
const footer = `
|
101
|
+
if (import.meta.hot) {
|
102
|
+
window.$RefreshReg$ = prevRefreshReg;
|
103
|
+
window.$RefreshSig$ = prevRefreshSig;
|
104
|
+
|
105
|
+
${checkAndAccept}
|
106
|
+
}`;
|
107
|
+
function addRefreshWrapper(code, id) {
|
108
|
+
return header.replace("__SOURCE__", JSON.stringify(id)) + code + footer;
|
137
109
|
}
|
138
110
|
|
139
111
|
const prependReactImportCode = "import React from 'react'; ";
|
@@ -294,11 +266,8 @@ function viteReact(opts = {}) {
|
|
294
266
|
if (/\.tsx?$/.test(extension)) {
|
295
267
|
parserPlugins.push("typescript");
|
296
268
|
}
|
297
|
-
const
|
298
|
-
const isReasonReact = extension.endsWith(".bs.js");
|
299
|
-
const result = await transformAsync({
|
269
|
+
const result = await babel.transformAsync(code, {
|
300
270
|
...babelOptions,
|
301
|
-
ast: !isReasonReact,
|
302
271
|
root: projectRoot,
|
303
272
|
filename: id,
|
304
273
|
sourceFileName: filepath,
|
@@ -319,8 +288,7 @@ function viteReact(opts = {}) {
|
|
319
288
|
if (result) {
|
320
289
|
let code2 = result.code;
|
321
290
|
if (useFastRefresh && /\$RefreshReg\$\(/.test(code2)) {
|
322
|
-
|
323
|
-
code2 = addRefreshWrapper(code2, id, accept);
|
291
|
+
code2 = addRefreshWrapper(code2, id);
|
324
292
|
}
|
325
293
|
return {
|
326
294
|
code: code2,
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@vitejs/plugin-react",
|
3
|
-
"version": "3.0.
|
3
|
+
"version": "3.0.1",
|
4
4
|
"license": "MIT",
|
5
5
|
"author": "Evan You",
|
6
6
|
"contributors": [
|
@@ -38,13 +38,13 @@
|
|
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.20.
|
41
|
+
"@babel/core": "^7.20.7",
|
42
42
|
"@babel/plugin-transform-react-jsx-self": "^7.18.6",
|
43
43
|
"@babel/plugin-transform-react-jsx-source": "^7.19.6",
|
44
44
|
"magic-string": "^0.27.0",
|
45
45
|
"react-refresh": "^0.14.0"
|
46
46
|
},
|
47
47
|
"peerDependencies": {
|
48
|
-
"vite": "^4.0.0
|
48
|
+
"vite": "^4.0.0"
|
49
49
|
}
|
50
50
|
}
|