o2o-infinith-frontend/vite.config.ts

44 lines
1.4 KiB
TypeScript

import path from 'node:path'
import tailwindcss from '@tailwindcss/vite'
import react from '@vitejs/plugin-react'
import { defineConfig, loadEnv } from 'vite'
export default defineConfig(({ mode }) => {
const env = loadEnv(mode, process.cwd(), '')
// Docker on macOS/Windows에서 파일 변경 감지를 위해 polling 필요
// CHOKIDAR_USEPOLLING=true 환경변수가 있을 때만 켬 (로컬 dev에선 비활성)
const usePolling = process.env.CHOKIDAR_USEPOLLING === 'true'
const apiTarget =
env.VITE_API_TARGET ||
env.VITE_API_BASE_URL ||
(usePolling ? 'http://host.docker.internal:8001' : 'http://localhost:8001')
return {
plugins: [react(), tailwindcss()],
resolve: {
alias: {
'@': path.resolve(__dirname, './src'),
},
},
// src/shared/api/api.ts 가 orval 의 mutator 로 cjs 번들될 때 `import.meta` 가 비어
// 경고가 뜨던 문제를 우회. Vite 가 빌드 타임에 아래 글로벌을 실값으로 치환한다.
define: {
__VITE_API_BASE_URL__: JSON.stringify(env.VITE_API_BASE_URL ?? ''),
__VITE_API_KEY__: JSON.stringify(env.VITE_API_KEY ?? ''),
},
server: {
port: 3000,
host: '0.0.0.0',
watch: usePolling ? { usePolling: true, interval: 300 } : undefined,
proxy: {
'/api': {
target: apiTarget,
changeOrigin: true,
},
},
},
}
})