File tree Expand file tree Collapse file tree 1 file changed +17
-8
lines changed
Expand file tree Collapse file tree 1 file changed +17
-8
lines changed Original file line number Diff line number Diff line change @@ -5,6 +5,22 @@ import { dotenv } from "zx";
55import { cloudflare } from "@cloudflare/vite-plugin" ;
66import * 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/
925export 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 ,
You can’t perform that action at this time.
0 commit comments