Skip to content

Commit d2ab32d

Browse files
committed
address feedback
1 parent 25fe5b5 commit d2ab32d

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

.changeset/beige-results-flow.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,10 @@
22
"@cloudflare/vite-plugin": patch
33
---
44

5-
fix: populate build time env var from `.env`
5+
Support Hyperdrive local connection strings from `.env` files
6+
7+
You can now define your Hyperdrive local connection string in a `.env` file using the `CLOUDFLARE_HYPERDRIVE_LOCAL_CONNECTION_STRING_<BINDING_NAME>` variable.
8+
9+
```sh
10+
CLOUDFLARE_HYPERDRIVE_LOCAL_CONNECTION_STRING_PROD_DB="postgres://user:[email protected]:5432/testdb"
11+
```

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,14 +112,15 @@ 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, [
115+
const prefixedEnv = vite.loadEnv(viteEnv.mode, root, [
116116
"CLOUDFLARE_",
117-
"WRANGLER_",
117+
// TODO: Remove deprecated WRANGLER prefix support in next major version
118+
"WRANGLER_HYPERDRIVE_LOCAL_CONNECTION_STRING_",
118119
]);
119120

120121
// Merge the loaded env variables into process.env so that they are available to
121122
// wrangler when it loads the worker configuration files.
122-
Object.assign(process.env, buildTimeEnv);
123+
Object.assign(process.env, prefixedEnv);
123124

124125
if (viteEnv.isPreview) {
125126
return {
@@ -130,7 +131,7 @@ export function resolvePluginConfig(
130131
}
131132

132133
const configPaths = new Set<string>();
133-
const cloudflareEnv = buildTimeEnv.CLOUDFLARE_ENV;
134+
const cloudflareEnv = prefixedEnv.CLOUDFLARE_ENV;
134135
const entryWorkerConfigPath = getValidatedWranglerConfigPath(
135136
root,
136137
pluginConfig.configPath

0 commit comments

Comments
 (0)