-
Notifications
You must be signed in to change notification settings - Fork 0
Description
Description
The current implementation of @rolldown/plugin-babel is asynchronous and returns a Promise<Plugin>. When using it in a Vite 8 project (especially for the React Compiler setup via reactCompilerPreset), it is often necessary to set Vite-specific properties like enforce: 'post'.
However, the returned Plugin type (likely following the core Rolldown/Rollup Hook interface) does not include these Vite-specific properties in its TypeScript definitions. Furthermore, because the function returns a Promise, developers must resolve it manually in the plugins array, which leads to poor ergonomics when a type cast is required to avoid TS errors.
Reproduction
In vite.config.ts:
import react, { reactCompilerPreset } from '@vitejs/plugin-react'
import babel from '@rolldown/plugin-babel';
export default defineConfig({
plugins: [
react(),
// This results in a type error: Property 'enforce' does not exist on type 'Plugin<any>'
babel({
presets: [reactCompilerPreset()]
}).then(p => {
p.enforce = 'post';
return p;
}),
]
})Current workaround:
babel({
presets: [reactCompilerPreset()]
}).then((p: any) => {
p.enforce = 'post';
return p;
}),Expected Behavior
Ideally, the plugin should be compatible with Vite's enforce and apply properties in its type definitions, or the React integration should offer a way to avoid this boilerplate. Since Vite 8 uses Rolldown as the engine, better alignment between Rolldown plugin types and Vite's expectations would improve the DX significantly.
Environment
@rolldown/plugin-babel:0.2.0vite:8.0.0-beta.16typescript:6.0.1-rc