@@ -6,8 +6,31 @@ import tailwindcss from "@tailwindcss/vite";
66import fs from "node:fs" ;
77import path from "node:path" ;
88
9- // Sanity config — dataset comes from env var (set by wrangler vars or .env)
10- // In astro.config.mjs, .env files are NOT loaded — use process.env
9+ // Load .env and .env.local into process.env before config runs.
10+ // (Using a function config with loadEnv broke virtual module resolution.)
11+ function loadEnvIntoProcess ( dir ) {
12+ for ( const name of [ ".env" , ".env.local" ] ) {
13+ const file = path . join ( dir , name ) ;
14+ try {
15+ const raw = fs . readFileSync ( file , "utf8" ) ;
16+ for ( const line of raw . split ( "\n" ) ) {
17+ const trimmed = line . trim ( ) ;
18+ if ( ! trimmed || trimmed . startsWith ( "#" ) ) continue ;
19+ const eq = trimmed . indexOf ( "=" ) ;
20+ if ( eq === - 1 ) continue ;
21+ const key = trimmed . slice ( 0 , eq ) . trim ( ) ;
22+ let value = trimmed . slice ( eq + 1 ) . trim ( ) ;
23+ if ( ( value . startsWith ( '"' ) && value . endsWith ( '"' ) ) || ( value . startsWith ( "'" ) && value . endsWith ( "'" ) ) )
24+ value = value . slice ( 1 , - 1 ) . replace ( / \\ ( .) / g, "$1" ) ;
25+ if ( ! Object . prototype . hasOwnProperty . call ( process . env , key ) ) process . env [ key ] = value ;
26+ }
27+ } catch {
28+ // ignore missing file
29+ }
30+ }
31+ }
32+ loadEnvIntoProcess ( process . cwd ( ) ) ;
33+
1134const sanityProjectId = process . env . SANITY_PROJECT_ID || "hfh83o0w" ;
1235const sanityDataset = process . env . SANITY_DATASET || "production" ;
1336
@@ -48,7 +71,7 @@ export default defineConfig({
4871 projectId : sanityProjectId ,
4972 dataset : sanityDataset ,
5073 useCdn : false ,
51- apiVersion : "2024-01-01 " ,
74+ apiVersion : "2026-03-17 " ,
5275 // Visual Editing: stega encodes edit markers in strings
5376 // Studio is standalone (apps/sanity), not embedded — no studioBasePath
5477 stega : {
@@ -61,6 +84,23 @@ export default defineConfig({
6184 plugins : [ tailwindcss ( ) , rawFonts ( [ ".ttf" , ".otf" ] ) ] ,
6285 assetsInclude : [ "**/*.wasm" ] ,
6386 assetsExclude : [ "**/*.ttf" , "**/*.otf" ] ,
87+ resolve : {
88+ alias : {
89+ // Sanity/visual-editing deps pull Node built-ins into client bundle; polyfill for browser
90+ stream : "stream-browserify" ,
91+ timers : "timers-browserify" ,
92+ } ,
93+ dedupe : [ "react" , "react-dom" , "react-is" , "react-compiler-runtime" ] ,
94+ } ,
95+ optimizeDeps : {
96+ // Force pre-bundle CJS deps so ESM default/named exports work in client (Sanity visual-editing chain)
97+ include : [
98+ "react-is" ,
99+ "react-compiler-runtime" ,
100+ "lodash" ,
101+ "lodash/isObject" ,
102+ ] ,
103+ } ,
64104 ssr : {
65105 external : [ "buffer" , "path" , "fs" ] . map ( ( i ) => `node:${ i } ` ) ,
66106 } ,
0 commit comments