Files
Reactive-Resume/apps/web/vite.config.ts
T
Amruth Pillai 73a3dfc423 fix(web): keep babel 7 so the react compiler compiles every component
Under @babel/core 8, babel-plugin-react-compiler 1.0 skipped every function with a destructuring default without saying so, which left about 70 components unmemoized, including every packages/ui primitive. A test compiles a component with a default prop through the same preset and fails if that comes back.
2026-09-29 18:13:06 +02:00

88 lines
2.5 KiB
TypeScript

import type { ProxyOptions } from "vite";
import { readFileSync } from "node:fs";
import { fileURLToPath } from "node:url";
import { lingui, linguiTransformerBabelPreset } from "@lingui/vite-plugin";
import babel from "@rolldown/plugin-babel";
import tailwindcss from "@tailwindcss/vite";
import { devtools } from "@tanstack/devtools-vite";
import { tanstackRouter } from "@tanstack/router-plugin/vite";
import viteReact, { reactCompilerPreset } from "@vitejs/plugin-react";
import { defineConfig } from "vite";
const rootPackageJsonPath = new URL("../../package.json", import.meta.url);
const rootPackageJson = JSON.parse(readFileSync(rootPackageJsonPath, "utf-8")) as { version: string | undefined };
const appVersion = JSON.stringify(rootPackageJson.version ?? "0.0.0");
const workspaceRoot = fileURLToPath(new URL("../..", import.meta.url));
const serverPaths = ["/api", "/mcp", "/uploads", "/.well-known", "/schema.json"] as const;
const serverProxy = serverPaths.reduce(
(acc, path) => {
acc[path] = {
target: `http://localhost:${process.env.SERVER_PORT ?? "3001"}`,
changeOrigin: true,
};
return acc;
},
{} as Record<string, ProxyOptions>,
);
export default defineConfig({
envDir: workspaceRoot,
resolve: {
tsconfigPaths: true,
},
define: {
__APP_VERSION__: appVersion,
},
build: {
chunkSizeWarningLimit: 10 * 1024, // 10 MB
rolldownOptions: {
external: ["bcrypt", "sharp", "@aws-sdk/client-s3", "ioredis", "linkedom"],
},
},
// 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()] })],
},
server: {
host: true,
strictPort: true,
port: Number.parseInt(process.env.PORT ?? "3000", 10),
proxy: serverProxy,
},
plugins: [
{
name: "cloudflare-rocket-loader-bootstrap",
transformIndexHtml: {
order: "post",
handler: (html) =>
html.replace(
/<script\b(?=[^>]*\btype="module")(?=[^>]*\bsrc="\/assets\/[^"]+")(?![^>]*\bdata-cfasync=)[^>]*>/,
(script) => script.replace('src="', 'data-cfasync="false" src="'),
),
},
},
devtools(),
tailwindcss(),
tanstackRouter({
target: "react",
semicolons: true,
quoteStyle: "double",
autoCodeSplitting: true,
}),
viteReact(),
lingui(),
// 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()] }),
],
});