fix(vite): only preserveSymlinks during dev, not build

Previous commit unconditionally enabled preserveSymlinks when
VITE_PRO_BUILD was set. That works for `vite dev` (where the overlay
is wired in via a Windows junction and the resolver needs to keep the
junction path so relative imports back into the OSS sibling dirs
resolve), but it BREAKS `vite build` in Docker — there are no symlinks
to preserve, and Rollup with preserveSymlinks=true fails to resolve
relative imports from the copied overlay tree:

    Could not resolve "../../../services/componentRegistry"
    from "src/pro/agent/tools/canvas.ts"

Gate the flag on `command === 'serve'` so it only kicks in during dev.
Production builds always run with preserveSymlinks=false (the default).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
David Montero Crespo 2026-05-08 01:18:31 -03:00
parent 78f990b04f
commit b83b6f28d6
1 changed files with 14 additions and 8 deletions

View File

@ -15,18 +15,24 @@ const proOverlayPath =
? path.resolve(process.env.PRO_OVERLAY_PATH)
: path.resolve(__dirname, 'src/__pro_stub__')
export default defineConfig({
export default defineConfig(({ command }) => ({
plugins: [react()],
resolve: {
alias: {
'@pro': proOverlayPath,
},
// When the pro overlay is wired in via a junction (Windows local-dev
// pattern), Vite's default resolution walks symlinks to the real path,
// which breaks relative imports from pro into upstream sibling dirs.
// Keeping the symlink-as-path lets `../../store/...` from pro resolve
// back into the OSS tree's src/.
preserveSymlinks: !!process.env.VITE_PRO_BUILD,
// Local dev only: when the pro overlay is wired in via a junction
// (Windows pattern: `frontend/src/pro` → `velxio-prod/pro/frontend/src/pro`),
// Vite's default resolver walks symlinks to the real path, which breaks
// relative imports like `../../store/...` from inside the overlay back
// into the OSS sibling dirs. Keeping the symlink-as-path fixes that.
//
// We do NOT enable this during `vite build` (Docker / CI): production
// builds COPY the overlay tree into the OSS frontend so there are no
// symlinks involved, and turning preserveSymlinks on there breaks
// Rollup's resolution of relative imports across the overlay/upstream
// boundary (real bug observed in Dockerfile.prod stage 1).
preserveSymlinks: command === 'serve' && !!process.env.VITE_PRO_BUILD,
},
server: {
proxy: {
@ -50,4 +56,4 @@ export default defineConfig({
reporter: ['text', 'html'],
},
},
})
}))