Skip to content

Commit b957cc6

Browse files
committed
chore: define the defines for vite.config.ts
1 parent 2f8157f commit b957cc6

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

dashboard/vite.config.ts

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,22 @@ import { dotenv } from "zx";
55
import { cloudflare } from "@cloudflare/vite-plugin";
66
import * as path from "path";
77

8+
function defines() {
9+
try {
10+
return Object.entries(dotenv.load(".dev.vars")).reduce(
11+
(acc, [key, value]) => {
12+
// Double stringify: once to make it a string, twice to make it a JSON string literal
13+
acc[`import.meta.env.${key}`] = JSON.stringify(value);
14+
return acc;
15+
},
16+
{} as Record<string, string>,
17+
);
18+
} catch (e) {
19+
console.warn("no .dev.vars found");
20+
return {};
21+
}
22+
}
23+
824
// https://vitejs.dev/config/
925
export default defineConfig({
1026
plugins: [
@@ -15,14 +31,7 @@ export default defineConfig({
1531
visualizer(),
1632
],
1733
define: {
18-
...Object.entries(dotenv.load(".dev.vars")).reduce(
19-
(acc, [key, value]) => {
20-
// Double stringify: once to make it a string, twice to make it a JSON string literal
21-
acc[`import.meta.env.${key}`] = JSON.stringify(value);
22-
return acc;
23-
},
24-
{} as Record<string, string>,
25-
),
34+
...defines(),
2635
},
2736
build: {
2837
sourcemap: true,

0 commit comments

Comments
 (0)