algospaced-dsa / algospaced-ui /vite.config.ts
iamfebin's picture
Configure AlgoSpaced for Hugging Face Spaces deployment
aaa634c
Raw
History Blame Contribute Delete
989 Bytes
import { defineConfig, loadEnv } from 'vite'
import react from '@vitejs/plugin-react'
import tailwindcss from '@tailwindcss/vite'
// https://vite.dev/config/
export default defineConfig(({ mode }) => {
const env = loadEnv(mode, process.cwd(), '')
const rawApiUrl = env.VITE_API_BASE_URL || 'http://localhost:8000'
return {
plugins: [react(), tailwindcss()],
define: {
'import.meta.env.VITE_API_BASE_URL': `(() => {
if (${mode === 'production'}) {
return '';
}
const base = ${JSON.stringify(rawApiUrl)};
if (typeof window !== 'undefined' && window.location) {
const hostname = window.location.hostname;
if (hostname && hostname !== 'localhost' && hostname !== '127.0.0.1') {
return base.replace('localhost', hostname).replace('127.0.0.1', hostname);
}
}
return base;
})()`
},
server: {
host: true, // Expose on local network (0.0.0.0)
}
}
})