Wire babel-plugin-react-compiler through @vitejs/plugin-react v6's reactCompilerPreset + @rolldown/plugin-babel in the web and desktop vite configs, scoped to modules that can actually contain components or hooks (JSX syntax or a react-ish import — the preset's default filter babel-parsed every TS module). Both vitest configs run compiled components, so rules-of-react violations fail in CI. Also fixes the latent bug the compiler exposed: usePluginI18n kept a stable translator identity over a mutating locale registry, so memoized consumers (React.memo today, compiled components tomorrow) served stale strings after a late bundle registration. The registry version now keys the translator identity — correct with or without the compiler.
25 lines
666 B
TypeScript
25 lines
666 B
TypeScript
import { defineConfig } from "vitest/config";
|
|
import babel from "@rolldown/plugin-babel";
|
|
import react, { reactCompilerPreset } from "@vitejs/plugin-react";
|
|
|
|
/** Same component/hook-scoped compiler preset as vite.config.ts. */
|
|
function compilerPreset() {
|
|
const preset = reactCompilerPreset();
|
|
preset.rolldown.filter.code = /\/>|<\/|from\s*['"][^'"]*react/;
|
|
return preset;
|
|
}
|
|
import path from "path";
|
|
|
|
export default defineConfig({
|
|
plugins: [react(), babel({ presets: [compilerPreset()] })],
|
|
resolve: {
|
|
alias: {
|
|
"@": path.resolve(__dirname, "./src"),
|
|
},
|
|
},
|
|
test: {
|
|
environment: "node",
|
|
include: ["src/**/*.test.{ts,tsx}"],
|
|
},
|
|
});
|