Skip to content

feat(react)!: remove babel#1123

Merged
sapphi-red merged 22 commits intomainfrom
feat/react-remove-babel
Mar 3, 2026
Merged

feat(react)!: remove babel#1123
sapphi-red merged 22 commits intomainfrom
feat/react-remove-babel

Conversation

@sapphi-red
Copy link
Copy Markdown
Member

@sapphi-red sapphi-red commented Feb 27, 2026

Description

Built on top of #1124

In Vite 8 (currently beta), react refresh transform can be handled by Oxc. This means there's no transform that uses babel by default.
To reduce the install size, I think we should remove babel from the dependency of @vitejs/plugin-react.

The @rolldown/plugin-babel package lives at https://github.com/rolldown/plugins.

context: #1114

@sapphi-red sapphi-red force-pushed the feat/react-remove-babel branch from 7a9ebf1 to a20730e Compare February 27, 2026 08:40
@sapphi-red sapphi-red changed the base branch from main to refactor/react-drop-vite7-and-below-support February 27, 2026 08:40
Copy link
Copy Markdown
Member

@ArnaudBarre ArnaudBarre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks cool, thanks for the cleanup, I'm happy I will be able stop downloading babel!
We need to updates the docs (both Readmes in the repo and vite.dev)
I think we should also add a section on how to add babel to a Vite 8 project, promoting this new plugin and all the possibilities for filtering.

function viteReactForCjs(this: unknown, options: Options): Plugin[] {
return viteReact.call(this, options)
}
Object.assign(viteReactForCjs, {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this needed when supporting only Vite 8+ which means require(esm) IIRM?

Copy link
Copy Markdown
Member Author

@sapphi-red sapphi-red Mar 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is needed to keep the value of require('@vitejs/plugin-react'). If we remove this, the config has to be:

const react = require('@vitejs/plugin-react')

module.exports = {
  plugins: [react.default()] // instead of `react()`
}

Base automatically changed from refactor/react-drop-vite7-and-below-support to main March 2, 2026 04:00
@sapphi-red sapphi-red marked this pull request as ready for review March 2, 2026 05:44
"noUnusedLocals": true,
"esModuleInterop": true
"esModuleInterop": true,
"rootDir": ".",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is rootDir needed? I thought this would allow importing it like import "src/any-file-inside-project" without type error and I didn't like that before.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is needed, otherwise I get the following error:

error TS2210: The project root is ambiguous, but is required to resolve import map entry '.' in file 'path/to/vite-plugin-react/packages/plugin-react/package.json'. Supply the rootDir compiler option to disambiguate.

I thought this would allow importing it like import "src/any-file-inside-project" without type error

I guess you are confused with baseUrl.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah good to know. Indeed, baseUrl is the one I hated 😅

@sapphi-red
Copy link
Copy Markdown
Member Author

I'll cut a beta version with this PR.

@sapphi-red sapphi-red merged commit ac16acc into main Mar 3, 2026
20 checks passed
@sapphi-red sapphi-red deleted the feat/react-remove-babel branch March 3, 2026 06:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants