fix(vite): inline import.meta.env.* (#3306)
This commit is contained in:
@@ -41,6 +41,18 @@ export function inlineEnvVarsPlugin(mode: string) {
|
||||
const name = path.node.property.name;
|
||||
replace(path, name);
|
||||
}
|
||||
|
||||
// Check: import.meta.env.*
|
||||
if (
|
||||
t.isIdentifier(path.node.property) &&
|
||||
t.isMemberExpression(path.node.object) &&
|
||||
t.isIdentifier(path.node.object.property) &&
|
||||
path.node.object.property.name === "env" &&
|
||||
t.isMetaProperty(path.node.object.object)
|
||||
) {
|
||||
const name = path.node.property.name;
|
||||
replace(path, name);
|
||||
}
|
||||
},
|
||||
CallExpression(path) {
|
||||
// Check: Deno.env.get("<string>")
|
||||
|
||||
@@ -69,3 +69,11 @@ Deno.test("env vars - inline const _ = Deno.env.get()", () => {
|
||||
expected: `const deno = "test";`,
|
||||
});
|
||||
});
|
||||
|
||||
Deno.test("env vars - inline import.meta.env.FRESH_PUBLIC_FOO", () => {
|
||||
using _ = usingEnv("FRESH_PUBLIC_FOO", "test");
|
||||
runTest({
|
||||
input: `() => import.meta.env.FRESH_PUBLIC_FOO;`,
|
||||
expected: `() => "test";`,
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user