Removing babel from @vitejs/plugin-react while having an easy way to add react compiler
#1114
Replies: 3 comments 2 replies
-
|
What about this? Is this possible? import babel from '@rollup/plugin-babel'
import react, { reactCompilerBabelPreset } from '@vitejs/plugin-react'
import { defineConfig } from 'vite'
export default defineConfig({
optimizeDeps: {
include: ['react-compiler-runtime'],
},
plugins: [
babel({ plugins: [reactCompilerBabelPreset] }),
react(),
],
}) |
Beta Was this translation helpful? Give feedback.
-
|
I don't think we should expose the whole thing as a Vite plugin, otherwise it makes it hard to add another babel plugin (or possibly not performant). There is also an option to keep the plugin as is, but make babel an optional peer dependency so it's not downloaded by default and if people want to use any plugin, we log an error message if it's not installed. It's the same number of deps for the users in their package.json in the end. But it's less coherent with the SWC deprecation. I like this idea of a rolldown babel plugin that knows Vite filters and can optimize the config when multiple filters are applied at the babel plugin level In the I think I prefer the
|
Beta Was this translation helpful? Give feedback.
-
|
We'll go with: import babel from '@rolldown/plugin-babel'
import react, { preconfiguredReactCompilerPlugin } from '@vitejs/plugin-react'
import { defineConfig } from 'vite'
export default defineConfig({
plugins: [
babel({
plugins: [
preconfiguredReactCompilerPlugin({ /* options */ })
]
}),
react(),
],
}) |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
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.That said, the React Compiler requires babel and we should make sure using that is still easy.
I've considered some ways to keep that easy, and would like to hear some thoughts about it.
Do nothing
As a reference, if we do nothing other than removing babel from
@vitejs/plugin-react, the config will be like this:The config is too long and I believe this is not acceptable.
Add
@rolldown/plugin-babelwith a better interfaceThe option passed to
@rollup/plugin-babelare huge mainly because the defaults are not decided based on what / how Vite / Rolldown supports. If we have a dedicated babel plugin for Vite & Rolldown, this will be solved. If we introduced that, the config will look like this:The default options are passed to babel internally by
@rolldown/plugin-babel. Hook filters andapplyToEnvironmentwill be computed based on the filter option passed along with the babel plugin.enforce: truewill be set by default.Users still need to set
optimizeDeps.includeand some filter by themselves, but it's much easier to configure.Add
@rolldown/plugin-babelwith a better interface + presetsSince many users will pass the same value for the filter option, probably it makes sense to provide a preset for that. If we introduced that, the config will look like this:
reactCompilerPluginAdapterwill have the filter options internally so that users won't have to specify it. Adapters can specifyoptimizeDeps.includeand@rolldown/plugin-babelwill set them internally so that users won't need to set them.This way users won't need to set any options.
Provide a preset from
@vitejs/plugin-reactI thought about providing a preset from
@vitejs/plugin-reactso that it's easier to use@rollup/plugin-babel.But to achieve that, the config looks like below, which makes me feel that the abstraction is wrong.
Beta Was this translation helpful? Give feedback.
All reactions