Skip to content

Commit 1576abe

Browse files
committed
fix(vite-plugin-cloudflare): populate build time env var from .env
1 parent f70377b commit 1576abe

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

packages/vite-plugin-cloudflare/src/plugin-config.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,16 @@ export function resolvePluginConfig(
122122
}
123123

124124
const configPaths = new Set<string>();
125-
const { CLOUDFLARE_ENV: cloudflareEnv } = vite.loadEnv(
126-
viteEnv.mode,
127-
root,
128-
/* prefixes */ ""
129-
);
125+
const buildTimeEnv = vite.loadEnv(viteEnv.mode, root, [
126+
"CLOUDFLARE_",
127+
"WRANGLER_",
128+
]);
129+
130+
// Merge the loaded env variables into process.env so that they are available to
131+
// wrangler when it loads the worker configuration files.
132+
Object.assign(process.env, buildTimeEnv);
130133

134+
const cloudflareEnv = buildTimeEnv.CLOUDFLARE_ENV;
131135
const entryWorkerConfigPath = getValidatedWranglerConfigPath(
132136
root,
133137
pluginConfig.configPath

0 commit comments

Comments
 (0)