fix(vite): inline FRESH_PUBLIC_* env vars (#3221)

This commit is contained in:
Marvin Hagemeister
2025-08-16 23:14:03 +02:00
committed by GitHub
parent 59549c9532
commit f80d049dca
7 changed files with 203 additions and 7 deletions
+9 -6
View File
@@ -3,6 +3,7 @@ import * as babel from "@babel/core";
import { cjsPlugin } from "./patches/commonjs.ts";
import { jsxComments } from "./patches/jsx_comment.ts";
import babelReact from "@babel/preset-react";
import { inlineEnvVarsPlugin } from "./patches/inline_env_vars.ts";
export function patches(): Plugin {
let isDev = false;
@@ -16,12 +17,8 @@ export function patches(): Plugin {
return true;
},
transform(code, id, options) {
if (code.includes("__commonJS") || /\.(tsx?|m[jt]s)$/.test(id)) {
return;
}
const presets = [];
if (!options?.ssr) {
if (!options?.ssr && /\.(tsx?|m[jt]s)$/.test(id)) {
presets.push([babelReact, {
runtime: "automatic",
importSource: "preact",
@@ -32,7 +29,13 @@ export function patches(): Plugin {
const res = babel.transformSync(code, {
filename: id,
babelrc: false,
plugins: [cjsPlugin, jsxComments],
plugins: [
cjsPlugin,
jsxComments,
inlineEnvVarsPlugin(
isDev ? "development" : "production",
),
],
presets,
});