Skip to content

Commit 0d94bb0

Browse files
fix(vite): inline import.meta.env.* (#3306)
1 parent ae2a27e commit 0d94bb0

2 files changed

Lines changed: 20 additions & 0 deletions

File tree

packages/plugin-vite/src/plugins/patches/inline_env_vars.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,18 @@ export function inlineEnvVarsPlugin(mode: string) {
4141
const name = path.node.property.name;
4242
replace(path, name);
4343
}
44+
45+
// Check: import.meta.env.*
46+
if (
47+
t.isIdentifier(path.node.property) &&
48+
t.isMemberExpression(path.node.object) &&
49+
t.isIdentifier(path.node.object.property) &&
50+
path.node.object.property.name === "env" &&
51+
t.isMetaProperty(path.node.object.object)
52+
) {
53+
const name = path.node.property.name;
54+
replace(path, name);
55+
}
4456
},
4557
CallExpression(path) {
4658
// Check: Deno.env.get("<string>")

packages/plugin-vite/src/plugins/patches/inline_env_vars_test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,11 @@ Deno.test("env vars - inline const _ = Deno.env.get()", () => {
6969
expected: `const deno = "test";`,
7070
});
7171
});
72+
73+
Deno.test("env vars - inline import.meta.env.FRESH_PUBLIC_FOO", () => {
74+
using _ = usingEnv("FRESH_PUBLIC_FOO", "test");
75+
runTest({
76+
input: `() => import.meta.env.FRESH_PUBLIC_FOO;`,
77+
expected: `() => "test";`,
78+
});
79+
});

0 commit comments

Comments
 (0)