58 lines
1.9 KiB
TypeScript
58 lines
1.9 KiB
TypeScript
import { defineConfig, loadEnv } from "vite"
|
|
import react from "@vitejs/plugin-react"
|
|
import wasm from "vite-plugin-wasm"
|
|
import topLevelAwait from "vite-plugin-top-level-await"
|
|
|
|
export default defineConfig(({ mode }) => {
|
|
// Load env file based on `mode` in the current working directory.
|
|
// Set the third parameter to '' to load all env regardless of the `VITE_` prefix.
|
|
const env = loadEnv(mode, process.cwd(), '')
|
|
|
|
// Debug: Log what we're getting
|
|
console.log('🔧 Vite config - Environment variables:')
|
|
console.log('Mode:', mode)
|
|
console.log('WSL2_IP from env:', process.env.WSL2_IP)
|
|
console.log('process.env.VITE_TLDRAW_WORKER_URL:', process.env.VITE_TLDRAW_WORKER_URL)
|
|
console.log('env.VITE_TLDRAW_WORKER_URL:', env.VITE_TLDRAW_WORKER_URL)
|
|
|
|
// Get the WSL2 IP for HMR configuration
|
|
const wslIp = process.env.WSL2_IP || '172.22.168.84'
|
|
|
|
// Set the worker URL to localhost for local development
|
|
const workerUrl = 'http://localhost:5172'
|
|
process.env.VITE_TLDRAW_WORKER_URL = workerUrl
|
|
console.log('🌐 Setting worker URL to:', workerUrl)
|
|
|
|
return {
|
|
envPrefix: ["VITE_"],
|
|
plugins: [react(), wasm(), topLevelAwait()],
|
|
server: {
|
|
host: "0.0.0.0",
|
|
port: 5173,
|
|
strictPort: true,
|
|
// Force IPv4 to ensure compatibility with WSL2 and remote devices
|
|
listen: "0.0.0.0",
|
|
// Configure HMR to use the correct hostname for WebSocket connections
|
|
hmr: {
|
|
host: wslIp,
|
|
port: 5173,
|
|
},
|
|
},
|
|
build: {
|
|
sourcemap: true,
|
|
},
|
|
base: "/",
|
|
publicDir: "src/public",
|
|
resolve: {
|
|
alias: {
|
|
"@": "/src",
|
|
},
|
|
},
|
|
define: {
|
|
// Worker URL is now handled dynamically in Board.tsx based on window.location.hostname
|
|
// This ensures remote devices connect to the correct worker IP
|
|
__DAILY_API_KEY__: JSON.stringify(process.env.VITE_DAILY_API_KEY || env.VITE_DAILY_API_KEY)
|
|
}
|
|
}
|
|
})
|