refactor: remove CJS and env var Babel transforms, let Vite handle natively (#3767)

## Summary

- **Replace Babel env var transforms with Vite's native `define`** —
`process.env.FRESH_PUBLIC_*` and `import.meta.env.FRESH_PUBLIC_*` now
use Vite's built-in `define` config. `Deno.env.get()` calls use a
lightweight regex-based transform (~10 lines vs 78-line Babel plugin).

- **Remove the 960-line CJS→ESM Babel transform** — Instead of
transforming CJS to ESM via Babel, let Vite handle CJS packages
natively:
- **Build mode**: Rollup's `@rollup/plugin-commonjs` handles CJS (always
has, but was bypassed by `deno.ts` loading through `@deno/loader`)
- **Dev mode**: A ~30-line CJS shim wraps `node_modules` CJS files with
`module`/`exports`/`require` so Vite's SSR module runner can evaluate
them
- `deno.ts` no longer attaches `meta.deno` to file:// resolved paths —
Vite loads them from disk directly

- **Remove `noDiscovery: true`** — Vite's dependency optimizer can now
pre-bundle CJS packages for the client

- **Fix React compat aliasing** — Apply `resolve.alias` (react →
preact/compat) in `deno.ts` before `@deno/loader` resolution, so the
alias works even when packages are non-external in SSR

Net: **~2,050 lines deleted**, ~150 lines added.

Fixes #3619, fixes #3653, fixes #3505, fixes #3478, fixes #3449.
This commit is contained in:
Bartek Iwańczuk
2026-04-25 14:40:11 +02:00
committed by GitHub
parent 13ed01fb40
commit b9a314ba1d
15 changed files with 190 additions and 2051 deletions
Generated
+12
View File
@@ -1,6 +1,7 @@
{
"version": "5",
"specifiers": {
"jsr:@astral/astral@0.5.6": "0.5.6",
"jsr:@astral/astral@~0.5.6": "0.5.6",
"jsr:@deno-library/progress@^1.5.1": "1.5.1",
"jsr:@deno/cache-dir@0.14": "0.14.0",
@@ -6110,6 +6111,17 @@
"npm:vite@^7.1.4"
]
}
},
"links": {
"npm:@deno/vite-plugin@2.0.2": {
"dependencies": [
"npm:@jsr/deno__loader@0.5",
"npm:@jsr/std__jsonc@1"
],
"peerDependencies": [
"npm:vite@5 || 6 || 7 || 8"
]
}
}
}
}