fix(vite): inline FRESH_PUBLIC_* env vars (#3221)
This commit is contained in:
@@ -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,
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user