fix(web): build the compiler preset without mutating it, from the config dir

Two changes that npm's hoisting hid and pnpm's layout exposes:

- reactCompilerPreset()'s rolldown.filter is optional once @vitejs/plugin-react's
  optional type peers resolve (TS18048 on the in-place assignment). Spread the
  preset instead of mutating it.
- Babel resolves preset plugin names from process.cwd(). Builders that run Vite
  from the checkout root (installer, Docker, Nix) only found
  babel-plugin-react-compiler because npm hoisted it there. Pass the config
  dir as babel's cwd.
This commit is contained in:
Maciej Lisiewski authored and Teknium committed 2026-11-05 14:08:26 -08:00
1 parent 0247bae91f
commit 1975266038
1 file changed
+10 -3
+10 -3
View File
@@ -8,8 +8,13 @@ import react, { reactCompilerPreset } from "@vitejs/plugin-react";
* module — which made the babel pass parse the whole codebase. */
function compilerPreset() {
const preset = reactCompilerPreset();
preset.rolldown.filter.code = /\/>|<\/|from\s*['"][^'"]*react/;
return preset;
return {
...preset,
rolldown: {
...preset.rolldown,
filter: { ...preset.rolldown.filter, code: /\/>|<\/|from\s*['"][^'"]*react/ },
},
};
}
import tailwindcss from "@tailwindcss/vite";
import path from "path";
@@ -84,7 +89,9 @@ export default defineConfig({
},
plugins: [
react(),
babel({ presets: [compilerPreset()] }),
// Babel resolves the compiler preset's plugin from its cwd; builders run Vite from the
// checkout root, where only this workspace's node_modules has it.
babel({ cwd: configDir, presets: [compilerPreset()] }),
tailwindcss(),
hermesDevToken(),
],