Skip to content

Commit ac16acc

Browse files
authored
feat(react)!: remove babel (#1123)
1 parent 28665e1 commit ac16acc

File tree

26 files changed

+641
-889
lines changed

26 files changed

+641
-889
lines changed

packages/plugin-react/CHANGELOG.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,55 @@
22

33
## Unreleased
44

5+
### Remove Babel Related Features ([#1123](https://github.com/vitejs/vite-plugin-react/pull/1123))
6+
7+
Vite 8+ can handle React Refresh Transform by Oxc and doesn't need Babel for it. With that, there are no transform applied that requires Babel. To reduce the installation size of this plugin, babel is no longer a dependency of this plugin and the related features are removed.
8+
9+
If you are using Babel, you can use `@rolldown/plugin-babel` together with this plugin:
10+
11+
```diff
12+
import { defineConfig } from 'vite'
13+
import react from '@vitejs/plugin-react'
14+
+import babel from '@rolldown/plugin-babel'
15+
16+
export default defineConfig({
17+
plugins: [
18+
- react({
19+
- babel: {
20+
- plugins: ['@babel/plugin-proposal-throw-expressions'],
21+
- },
22+
- }),
23+
+ react(),
24+
+ babel({
25+
+ plugins: ['@babel/plugin-proposal-throw-expressions'],
26+
+ }),
27+
]
28+
})
29+
```
30+
31+
For React compiler users, you can use `reactCompilerPreset` for easier setup with preconfigured filter to improve build performance:
32+
33+
```diff
34+
import { defineConfig } from 'vite'
35+
-import react from '@vitejs/plugin-react'
36+
+import react, { reactCompilerPreset } from '@vitejs/plugin-react'
37+
+import babel from '@rolldown/plugin-babel'
38+
39+
export default defineConfig({
40+
plugins: [
41+
- react({
42+
- babel: {
43+
- plugins: ['babel-plugin-react-compiler'],
44+
- },
45+
- }),
46+
+ react(),
47+
+ babel({
48+
+ presets: [reactCompilerPreset()]
49+
+ }),
50+
]
51+
})
52+
```
53+
554
### Drop Vite 7 and below support ([#1124](https://github.com/vitejs/vite-plugin-react/pull/1124))
655

756
Vite 7 and below are no longer supported. If you are using Vite 7, please upgrade to Vite 8.

packages/plugin-react/README.md

Lines changed: 23 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ The default Vite plugin for React projects.
44

55
- enable [Fast Refresh](https://www.npmjs.com/package/react-refresh) in development (requires react >= 16.9)
66
- use the [automatic JSX runtime](https://legacy.reactjs.org/blog/2020/09/22/introducing-the-new-jsx-transform.html)
7-
- use custom Babel plugins/presets
87
- small installation size
98

109
```js
@@ -68,56 +67,46 @@ By default, the plugin uses the [automatic JSX runtime](https://legacy.reactjs.o
6867
react({ jsxRuntime: 'classic' })
6968
```
7069

71-
### babel
70+
### reactRefreshHost
7271

73-
The `babel` option lets you add plugins, presets, and [other configuration](https://babeljs.io/docs/en/options) to the Babel transformation performed on each included file.
72+
The `reactRefreshHost` option is only necessary in a module federation context. It enables HMR to work between a remote & host application. In your remote Vite config, you would add your host origin:
7473

7574
```js
76-
react({
77-
babel: {
78-
presets: [...],
79-
// Your plugins run before any built-in transform (eg: Fast Refresh)
80-
plugins: [...],
81-
// Use .babelrc files
82-
babelrc: true,
83-
// Use babel.config.js files
84-
configFile: true,
85-
}
86-
})
75+
react({ reactRefreshHost: 'http://localhost:3000' })
8776
```
8877

89-
Note: When not using plugins, only esbuild is used for production builds, resulting in faster builds.
78+
Under the hood, this simply updates the React Fash Refresh runtime URL from `/@react-refresh` to `http://localhost:3000/@react-refresh` to ensure there is only one Refresh runtime across the whole application. Note that if you define `base` option in the host application, you need to include it in the option, like: `http://localhost:3000/{base}`.
9079

91-
#### Proposed syntax
80+
## React Compiler
9281

93-
If you are using ES syntax that are still in proposal status (e.g. class properties), you can selectively enable them with the `babel.parserOpts.plugins` option:
82+
[React Compiler](https://react.dev/learn/react-compiler) support is available via the exported `reactCompilerPreset` helper, which requires [`@rolldown/plugin-babel`](https://npmx.dev/package/@rolldown/plugin-babel) and [`babel-plugin-react-compiler`](https://npmx.dev/package/babel-plugin-react-compiler) as peer dependencies:
9483

95-
```js
96-
react({
97-
babel: {
98-
parserOpts: {
99-
plugins: ['decorators-legacy'],
100-
},
101-
},
102-
})
84+
```sh
85+
npm install -D @rolldown/plugin-babel babel-plugin-react-compiler
10386
```
10487

105-
This option does not enable _code transformation_. That is handled by esbuild.
106-
107-
**Note:** TypeScript syntax is handled automatically.
88+
```js
89+
// vite.config.js
90+
import { defineConfig } from 'vite'
91+
import react, { reactCompilerPreset } from '@vitejs/plugin-react'
92+
import babel from '@rolldown/plugin-babel'
10893

109-
Here's the [complete list of Babel parser plugins](https://babeljs.io/docs/en/babel-parser#ecmascript-proposalshttpsgithubcombabelproposals).
94+
export default defineConfig({
95+
plugins: [react(), babel({ presets: [reactCompilerPreset()] })],
96+
})
97+
```
11098

111-
### reactRefreshHost
99+
The `reactCompilerPreset` accepts an optional options object with the following properties:
112100

113-
The `reactRefreshHost` option is only necessary in a module federation context. It enables HMR to work between a remote & host application. In your remote Vite config, you would add your host origin:
101+
- `compilationMode` — Set to `'annotation'` to only compile components annotated with `"use memo"`.
102+
- `target` — Set to `'17'` or `'18'` to target older React versions (uses `react-compiler-runtime` instead of `react/compiler-runtime`).
114103

115104
```js
116-
react({ reactRefreshHost: 'http://localhost:3000' })
105+
babel({
106+
presets: [reactCompilerPreset({ compilationMode: 'annotation' })],
107+
})
117108
```
118109

119-
Under the hood, this simply updates the React Fash Refresh runtime URL from `/@react-refresh` to `http://localhost:3000/@react-refresh` to ensure there is only one Refresh runtime across the whole application. Note that if you define `base` option in the host application, you need to include it in the option, like: `http://localhost:3000/{base}`.
120-
121110
## `@vitejs/plugin-react/preamble`
122111

123112
The package provides `@vitejs/plugin-react/preamble` to initialize HMR runtime from client entrypoint for SSR applications which don't use [`transformIndexHtml` API](https://vite.dev/guide/api-javascript.html#vitedevserver). For example:

packages/plugin-react/package.json

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
"version": "5.1.4",
44
"description": "The default Vite plugin for React projects",
55
"keywords": [
6-
"babel",
76
"fast refresh",
87
"react",
98
"react-refresh",
@@ -30,6 +29,9 @@
3029
"types"
3130
],
3231
"type": "module",
32+
"imports": {
33+
"#optionalTypes": "./types/optionalTypes.d.ts"
34+
},
3335
"exports": {
3436
".": "./dist/index.js",
3537
"./preamble": "./types/preamble.d.ts"
@@ -41,24 +43,32 @@
4143
"test-unit": "vitest run"
4244
},
4345
"dependencies": {
44-
"@babel/core": "^7.29.0",
45-
"@babel/plugin-transform-react-jsx-self": "^7.27.1",
46-
"@babel/plugin-transform-react-jsx-source": "^7.27.1",
47-
"@rolldown/pluginutils": "1.0.0-rc.6",
48-
"@types/babel__core": "^7.20.5"
46+
"@rolldown/pluginutils": "1.0.0-rc.6"
4947
},
5048
"devDependencies": {
49+
"@babel/core": "8.0.0-rc.2",
50+
"@rolldown/plugin-babel": "^0.1.7",
5151
"@vitejs/react-common": "workspace:*",
52-
"babel-plugin-react-compiler": "19.1.0-rc.3",
52+
"babel-plugin-react-compiler": "^1.0.0",
5353
"react": "^19.2.4",
5454
"react-dom": "^19.2.4",
5555
"rolldown": "1.0.0-rc.6",
5656
"tsdown": "^0.20.3",
5757
"vite": "^8.0.0-beta.16"
5858
},
5959
"peerDependencies": {
60+
"@rolldown/plugin-babel": "^0.1.7",
61+
"babel-plugin-react-compiler": "^1.0.0",
6062
"vite": "^8.0.0"
6163
},
64+
"peerDependenciesMeta": {
65+
"@rolldown/plugin-babel": {
66+
"optional": true
67+
},
68+
"babel-plugin-react-compiler": {
69+
"optional": true
70+
}
71+
},
6272
"engines": {
6373
"node": "^20.19.0 || >=22.12.0"
6474
},

packages/plugin-react/src/babel.d.ts

Lines changed: 0 additions & 2 deletions
This file was deleted.

0 commit comments

Comments
 (0)