Repository navigation
Replies: 2 comments
|
it works,refer to https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md import { reactRouter } from '@react-router/dev/vite'
import tailwindcss from '@tailwindcss/vite'
import { defineConfig } from 'vite'
import { reactCompilerPreset } from '@vitejs/plugin-react'
import babel from '@rolldown/plugin-babel'
export default defineConfig({
plugins: [tailwindcss(), reactRouter(), babel({ presets: [reactCompilerPreset()] })],
resolve: {
tsconfigPaths: true,
},
}) |
|
@xiaohp's snippet is the right shape, and it matches the official React Compiler install guide for Vite: run the compiler as a separate Babel pass via // vite.config.ts
import { reactRouter } from "@react-router/dev/vite";
import babel from "@rolldown/plugin-babel";
import { reactCompilerPreset } from "@vitejs/plugin-react";
import { defineConfig } from "vite";
export default defineConfig({
plugins: [
reactRouter(),
babel({
// only transform app source; node_modules is already excluded by default
include: /\.[jt]sx?$/,
presets: [reactCompilerPreset()],
}),
],
});npm i -D @rolldown/plugin-babel babel-plugin-react-compiler react-compiler-runtimeWhy you don't (and shouldn't) add
|
Uh oh!
There was an error while loading. Please reload this page.
What I'm trying to do Enable
babel-plugin-react-compilerin a React Router v7 framework-mode app, the same way I would in a plain Vite + React app.Context
With
@vitejs/plugin-reactit's documented and one-liner:The problem in framework mode
@react-router/dev'sreactRouter()plugin does its own JSX/Fast-Refresh transformation and does not expose any option to inject a Babel plugin. The plugin's TypeScript signature is literally zero-arg:Internally the JSX transform is hard-coded:
No babel option, no
reactCompilerfield, no escape hatch.What I've tried
@vitejs/plugin-reactalongsidereactRouter(). Either React Refresh runs twice (errors out), or the order matters and it breaks HMR. Not viable without a docs-sanctioned configuration.reactRouter()accepts nothing. I read the source to confirm there's no internal hook.use clientboundary. That suggests the team has at least heard of users running the Compiler against framework mode, but there's no guidance.Questions for the team
babel-plugin-react-compilerofficially supported in framework mode today? If not, is it on the roadmap?babeloption onreactRouter()? A separate plugin? Avite.config.tsoptimizeDepsworkaround?reactRouter()is the only "blessed" path into framework mode, so without a way to configure it users are stuck choosing between React Router and React Compiler.Proposed API (one option to consider)
If a config knob is on the table, something like this would close the gap without breaking existing setups:
Or, alternatively, document explicitly that users should compose
@vitejs/plugin-reactbeforereactRouter()(or after) with a specific ordering, and confirm the resulting HMR behavior is correct.Happy to test either path on a real app and report back. Thanks!
All reactions