@vitejs/plugin-react 4.5.1 → 4.6.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/README.md +4 -0
- package/dist/index.cjs +18 -2
- package/dist/index.d.cts +4 -0
- package/dist/index.d.mts +4 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.mjs +18 -2
- package/package.json +14 -8
package/README.md
CHANGED
@@ -129,6 +129,10 @@ Otherwise, you'll probably get this error:
|
|
129
129
|
Uncaught Error: @vitejs/plugin-react can't detect preamble. Something is wrong.
|
130
130
|
```
|
131
131
|
|
132
|
+
### disableOxcRecommendation
|
133
|
+
|
134
|
+
If set, disables the recommendation to use `@vitejs/plugin-react-oxc` (which is shown when `rolldown-vite` is detected and `babel` is not configured).
|
135
|
+
|
132
136
|
## Consistent components exports
|
133
137
|
|
134
138
|
For React refresh to work correctly, your file should only export React components. You can find a good explanation in the [Gatsby docs](https://www.gatsbyjs.com/docs/reference/local-development/fast-refresh/#how-it-works).
|
package/dist/index.cjs
CHANGED
@@ -141,9 +141,10 @@ function viteReact(opts = {}) {
|
|
141
141
|
const jsxImportSource = opts.jsxImportSource ?? "react";
|
142
142
|
const jsxImportRuntime = `${jsxImportSource}/jsx-runtime`;
|
143
143
|
const jsxImportDevRuntime = `${jsxImportSource}/jsx-dev-runtime`;
|
144
|
+
let runningInVite = false;
|
144
145
|
let isProduction = true;
|
145
146
|
let projectRoot = process.cwd();
|
146
|
-
let skipFastRefresh =
|
147
|
+
let skipFastRefresh = true;
|
147
148
|
let runPluginOverrides;
|
148
149
|
let staticBabelOptions;
|
149
150
|
const importReactRE = /\bimport\s+(?:\*\s+as\s+)?React\b/;
|
@@ -177,11 +178,12 @@ function viteReact(opts = {}) {
|
|
177
178
|
jsx: "automatic",
|
178
179
|
jsxImportSource: opts.jsxImportSource
|
179
180
|
},
|
180
|
-
optimizeDeps: { esbuildOptions: { jsx: "automatic" } }
|
181
|
+
optimizeDeps: "rolldownVersion" in vite__namespace ? { rollupOptions: { jsx: { mode: "automatic" } } } : { esbuildOptions: { jsx: "automatic" } }
|
181
182
|
};
|
182
183
|
}
|
183
184
|
},
|
184
185
|
configResolved(config) {
|
186
|
+
runningInVite = true;
|
185
187
|
projectRoot = config.root;
|
186
188
|
isProduction = config.isProduction;
|
187
189
|
skipFastRefresh = isProduction || config.command === "build" || config.server.hmr === false;
|
@@ -191,6 +193,11 @@ function viteReact(opts = {}) {
|
|
191
193
|
);
|
192
194
|
}
|
193
195
|
const hooks = config.plugins.map((plugin) => plugin.api?.reactBabel).filter(defined);
|
196
|
+
if ("rolldownVersion" in vite__namespace && !opts.babel && !hooks.length && !opts.disableOxcRecommendation) {
|
197
|
+
config.logger.warn(
|
198
|
+
"[vite:react-babel] We recommend switching to `@vitejs/plugin-react-oxc` for improved performance. More information at https://vite.dev/rolldown"
|
199
|
+
);
|
200
|
+
}
|
194
201
|
if (hooks.length > 0) {
|
195
202
|
runPluginOverrides = (babelOptions, context) => {
|
196
203
|
hooks.forEach((hook) => hook(babelOptions, context, config));
|
@@ -202,6 +209,15 @@ function viteReact(opts = {}) {
|
|
202
209
|
}
|
203
210
|
}
|
204
211
|
},
|
212
|
+
options(options) {
|
213
|
+
if (!runningInVite) {
|
214
|
+
options.jsx = {
|
215
|
+
mode: opts.jsxRuntime,
|
216
|
+
importSource: opts.jsxImportSource
|
217
|
+
};
|
218
|
+
return options;
|
219
|
+
}
|
220
|
+
},
|
205
221
|
transform: {
|
206
222
|
filter: {
|
207
223
|
id: {
|
package/dist/index.d.cts
CHANGED
@@ -29,6 +29,10 @@ interface Options {
|
|
29
29
|
* reactRefreshHost: 'http://localhost:3000'
|
30
30
|
*/
|
31
31
|
reactRefreshHost?: string;
|
32
|
+
/**
|
33
|
+
* If set, disables the recommendation to use `@vitejs/plugin-react-oxc`
|
34
|
+
*/
|
35
|
+
disableOxcRecommendation?: boolean;
|
32
36
|
}
|
33
37
|
type BabelOptions = Omit<TransformOptions, 'ast' | 'filename' | 'root' | 'sourceFileName' | 'sourceMaps' | 'inputSourceMap'>;
|
34
38
|
/**
|
package/dist/index.d.mts
CHANGED
@@ -29,6 +29,10 @@ interface Options {
|
|
29
29
|
* reactRefreshHost: 'http://localhost:3000'
|
30
30
|
*/
|
31
31
|
reactRefreshHost?: string;
|
32
|
+
/**
|
33
|
+
* If set, disables the recommendation to use `@vitejs/plugin-react-oxc`
|
34
|
+
*/
|
35
|
+
disableOxcRecommendation?: boolean;
|
32
36
|
}
|
33
37
|
type BabelOptions = Omit<TransformOptions, 'ast' | 'filename' | 'root' | 'sourceFileName' | 'sourceMaps' | 'inputSourceMap'>;
|
34
38
|
/**
|
package/dist/index.d.ts
CHANGED
@@ -29,6 +29,10 @@ interface Options {
|
|
29
29
|
* reactRefreshHost: 'http://localhost:3000'
|
30
30
|
*/
|
31
31
|
reactRefreshHost?: string;
|
32
|
+
/**
|
33
|
+
* If set, disables the recommendation to use `@vitejs/plugin-react-oxc`
|
34
|
+
*/
|
35
|
+
disableOxcRecommendation?: boolean;
|
32
36
|
}
|
33
37
|
type BabelOptions = Omit<TransformOptions, 'ast' | 'filename' | 'root' | 'sourceFileName' | 'sourceMaps' | 'inputSourceMap'>;
|
34
38
|
/**
|
package/dist/index.mjs
CHANGED
@@ -125,9 +125,10 @@ function viteReact(opts = {}) {
|
|
125
125
|
const jsxImportSource = opts.jsxImportSource ?? "react";
|
126
126
|
const jsxImportRuntime = `${jsxImportSource}/jsx-runtime`;
|
127
127
|
const jsxImportDevRuntime = `${jsxImportSource}/jsx-dev-runtime`;
|
128
|
+
let runningInVite = false;
|
128
129
|
let isProduction = true;
|
129
130
|
let projectRoot = process.cwd();
|
130
|
-
let skipFastRefresh =
|
131
|
+
let skipFastRefresh = true;
|
131
132
|
let runPluginOverrides;
|
132
133
|
let staticBabelOptions;
|
133
134
|
const importReactRE = /\bimport\s+(?:\*\s+as\s+)?React\b/;
|
@@ -161,11 +162,12 @@ function viteReact(opts = {}) {
|
|
161
162
|
jsx: "automatic",
|
162
163
|
jsxImportSource: opts.jsxImportSource
|
163
164
|
},
|
164
|
-
optimizeDeps: { esbuildOptions: { jsx: "automatic" } }
|
165
|
+
optimizeDeps: "rolldownVersion" in vite ? { rollupOptions: { jsx: { mode: "automatic" } } } : { esbuildOptions: { jsx: "automatic" } }
|
165
166
|
};
|
166
167
|
}
|
167
168
|
},
|
168
169
|
configResolved(config) {
|
170
|
+
runningInVite = true;
|
169
171
|
projectRoot = config.root;
|
170
172
|
isProduction = config.isProduction;
|
171
173
|
skipFastRefresh = isProduction || config.command === "build" || config.server.hmr === false;
|
@@ -175,6 +177,11 @@ function viteReact(opts = {}) {
|
|
175
177
|
);
|
176
178
|
}
|
177
179
|
const hooks = config.plugins.map((plugin) => plugin.api?.reactBabel).filter(defined);
|
180
|
+
if ("rolldownVersion" in vite && !opts.babel && !hooks.length && !opts.disableOxcRecommendation) {
|
181
|
+
config.logger.warn(
|
182
|
+
"[vite:react-babel] We recommend switching to `@vitejs/plugin-react-oxc` for improved performance. More information at https://vite.dev/rolldown"
|
183
|
+
);
|
184
|
+
}
|
178
185
|
if (hooks.length > 0) {
|
179
186
|
runPluginOverrides = (babelOptions, context) => {
|
180
187
|
hooks.forEach((hook) => hook(babelOptions, context, config));
|
@@ -186,6 +193,15 @@ function viteReact(opts = {}) {
|
|
186
193
|
}
|
187
194
|
}
|
188
195
|
},
|
196
|
+
options(options) {
|
197
|
+
if (!runningInVite) {
|
198
|
+
options.jsx = {
|
199
|
+
mode: opts.jsxRuntime,
|
200
|
+
importSource: opts.jsxImportSource
|
201
|
+
};
|
202
|
+
return options;
|
203
|
+
}
|
204
|
+
},
|
189
205
|
transform: {
|
190
206
|
filter: {
|
191
207
|
id: {
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@vitejs/plugin-react",
|
3
|
-
"version": "4.
|
3
|
+
"version": "4.6.0",
|
4
4
|
"license": "MIT",
|
5
5
|
"author": "Evan You",
|
6
6
|
"description": "The default Vite plugin for React projects",
|
@@ -33,7 +33,8 @@
|
|
33
33
|
"dev": "unbuild --stub",
|
34
34
|
"build": "unbuild && pnpm run patch-cjs && tsx scripts/copyRefreshRuntime.ts",
|
35
35
|
"patch-cjs": "tsx ../../scripts/patchCJS.ts",
|
36
|
-
"prepublishOnly": "npm run build"
|
36
|
+
"prepublishOnly": "npm run build",
|
37
|
+
"test-unit": "vitest run"
|
37
38
|
},
|
38
39
|
"engines": {
|
39
40
|
"node": "^14.18.0 || >=16.0.0"
|
@@ -48,18 +49,23 @@
|
|
48
49
|
},
|
49
50
|
"homepage": "https://github.com/vitejs/vite-plugin-react/tree/main/packages/plugin-react#readme",
|
50
51
|
"dependencies": {
|
51
|
-
"@babel/core": "^7.
|
52
|
-
"@babel/plugin-transform-react-jsx-self": "^7.
|
53
|
-
"@babel/plugin-transform-react-jsx-source": "^7.
|
54
|
-
"@rolldown/pluginutils": "1.0.0-beta.
|
52
|
+
"@babel/core": "^7.27.4",
|
53
|
+
"@babel/plugin-transform-react-jsx-self": "^7.27.1",
|
54
|
+
"@babel/plugin-transform-react-jsx-source": "^7.27.1",
|
55
|
+
"@rolldown/pluginutils": "1.0.0-beta.19",
|
55
56
|
"@types/babel__core": "^7.20.5",
|
56
57
|
"react-refresh": "^0.17.0"
|
57
58
|
},
|
58
59
|
"peerDependencies": {
|
59
|
-
"vite": "^4.2.0 || ^5.0.0 || ^6.0.0"
|
60
|
+
"vite": "^4.2.0 || ^5.0.0 || ^6.0.0 || ^7.0.0-beta.0"
|
60
61
|
},
|
61
62
|
"devDependencies": {
|
62
63
|
"@vitejs/react-common": "workspace:*",
|
63
|
-
"
|
64
|
+
"babel-plugin-react-compiler": "19.1.0-rc.2",
|
65
|
+
"react": "^19.1.0",
|
66
|
+
"react-dom": "^19.1.0",
|
67
|
+
"rolldown": "1.0.0-beta.19",
|
68
|
+
"unbuild": "^3.5.0",
|
69
|
+
"vitest": "^3.2.4"
|
64
70
|
}
|
65
71
|
}
|