build(web): use Lingui's native macro transform instead of Babel

The Lingui Vite plugin transforms macros itself, so the Babel preset and
its plugin dependency go. TanStack Router's split-route query hides the
`.tsx` extension, so the parser is told to read TSX explicitly.
This commit is contained in:
Amruth Pillai
2026-10-01 23:00:52 +02:00
parent b63170c5f1
commit 36f2477c2a
3 changed files with 11 additions and 8 deletions
-1
View File
@@ -93,7 +93,6 @@
},
"devDependencies": {
"@babel/core": "^7.29.7",
"@lingui/babel-plugin-lingui-macro": "^6.9.0",
"@lingui/cli": "^6.9.0",
"@lingui/format-po": "^6.9.0",
"@lingui/vite-plugin": "^6.9.0",
+9 -4
View File
@@ -2,7 +2,7 @@ import type { ProxyOptions } from "vite";
import { readFileSync } from "node:fs";
import { mkdir, readFile, rm, writeFile } from "node:fs/promises";
import { fileURLToPath, pathToFileURL } from "node:url";
import { lingui, linguiTransformerBabelPreset } from "@lingui/vite-plugin";
import { lingui } from "@lingui/vite-plugin";
import babel from "@rolldown/plugin-babel";
import tailwindcss from "@tailwindcss/vite";
import { devtools } from "@tanstack/devtools-vite";
@@ -55,6 +55,11 @@ async function prerenderPages() {
}
}
// TanStack Router loads `route.tsx?tsr-split=…`. The native parser infers syntax from the filename,
// and the query hides `.tsx`, so JSX is parsed as JS.
const linguiPlugin = () =>
lingui({ macroTransform: { parser: { syntax: "typescript", tsx: true, decorators: true } } });
const serverPaths = ["/api", "/mcp", "/uploads", "/.well-known", "/schema.json"] as const;
const serverProxy = serverPaths.reduce(
@@ -110,7 +115,7 @@ export default defineConfig({
// The PDF worker renders templates with translated section titles, so it needs the catalogs and macros too.
worker: {
format: "es",
plugins: () => [lingui(), babel({ presets: [linguiTransformerBabelPreset()] })],
plugins: () => [linguiPlugin()],
},
server: {
@@ -141,9 +146,9 @@ export default defineConfig({
autoCodeSplitting: true,
}),
viteReact(),
lingui(),
linguiPlugin(),
// Keep @babel/core on 7: under Babel 8, React Compiler 1.0 skips every function with a destructuring default
// (guarded by src/react-compiler.test.ts).
babel({ presets: [reactCompilerPreset(), linguiTransformerBabelPreset()] }),
babel({ presets: [reactCompilerPreset()] }),
],
});
+2 -3
View File
@@ -1,6 +1,5 @@
import { fileURLToPath } from "node:url";
import { lingui, linguiTransformerBabelPreset } from "@lingui/vite-plugin";
import babel from "@rolldown/plugin-babel";
import { lingui } from "@lingui/vite-plugin";
import tailwindcss from "@tailwindcss/vite";
// @boundaries-ignore root shared Vitest config
import { createVitestProjectConfig } from "../../vitest.shared.mts";
@@ -8,5 +7,5 @@ import { createVitestProjectConfig } from "../../vitest.shared.mts";
export default createVitestProjectConfig({
name: "web",
dirname: fileURLToPath(new URL(".", import.meta.url)),
plugins: [tailwindcss(), lingui(), babel({ presets: [linguiTransformerBabelPreset()] })],
plugins: [tailwindcss(), lingui({ macroTransform: true })],
});