## Summary Fixes several issues in the Fresh Vite plugin's CommonJS-to-ESM Babel transform (`commonjs.ts`) that caused npm packages to break during builds while working fine in dev mode. - **Fix `.mts`/`.cts` extension detection** — `.cts` was incorrectly in the ESM branch (should be `.mts`), causing TypeScript CJS files to skip the transform - **Handle `require.resolve()`** — injects `createRequire(import.meta.url)` polyfill so `require.resolve()` calls work in ESM output (#3619) - **Polyfill `__dirname`/`__filename`** — injects `fileURLToPath`/`dirname` based polyfill when these CJS globals are used - **Use `var` instead of `let` for `_default`** — avoids TDZ errors when Rollup reorders declarations in bundled output (#3653) - **Track `module.exports.X` as named exports** — the MemberExpression visitor now handles both `exports.X` and `module.exports.X` patterns Addresses: #3619, #3653 --------- Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Fresh vite plugin
Vite plugin for Fresh.
Usage
- Run
deno install jsr:@fresh/plugin-vite npm:vite - Ensure that your
deno.jsonhas thefreshimport mapping:
{
"imports": {
"fresh": "jsr:@fresh/core"
}
}
- Update your
vite.config.tsfile:
import { defineConfig } from "vite";
+ import { fresh } from "@fresh/plugin-vite";
export default defineConfig({
plugins: [
+ fresh(),
],
});
- Update your deno tasks respectively:
- Dev:
vite - Build:
vite build
More information on the Fresh documentation .