Skip to content

Commit 36be04a

Browse files
committed
populate env var earlier to support vite preview
1 parent 1576abe commit 36be04a

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

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

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,14 @@ export function resolvePluginConfig(
112112
experimental: pluginConfig.experimental ?? {},
113113
};
114114
const root = userConfig.root ? path.resolve(userConfig.root) : process.cwd();
115+
const buildTimeEnv = vite.loadEnv(viteEnv.mode, root, [
116+
"CLOUDFLARE_",
117+
"WRANGLER_",
118+
]);
119+
120+
// Merge the loaded env variables into process.env so that they are available to
121+
// wrangler when it loads the worker configuration files.
122+
Object.assign(process.env, buildTimeEnv);
115123

116124
if (viteEnv.isPreview) {
117125
return {
@@ -122,15 +130,6 @@ export function resolvePluginConfig(
122130
}
123131

124132
const configPaths = new Set<string>();
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);
133-
134133
const cloudflareEnv = buildTimeEnv.CLOUDFLARE_ENV;
135134
const entryWorkerConfigPath = getValidatedWranglerConfigPath(
136135
root,

0 commit comments

Comments
 (0)