Files
smart-project/h5-app/vite.config.ts
jesxion a994c8d076 fix: harden ant mobile scaffold config
- vite.config.ts: use loadEnv() to read VITE_BASE (base path) and
  DEV_API_TARGET (proxy target) from .env; falls back to '/' and
  http://127.0.0.1:3201 so local dev is unchanged
- App.tsx: pass basename={import.meta.env.BASE_URL} to BrowserRouter
  so router paths align with the Vite base at runtime
- global.css: change #root overflow from hidden to auto so page
  content is scrollable
- .env: document VITE_BASE, VITE_API_BASE, DEV_API_TARGET defaults
- src/config.ts: expose apiBase helper for runtime API prefix
- tsconfig.json: add vite/client types so import.meta.env is typed

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-24 16:42:24 +08:00

25 lines
618 B
TypeScript

import { defineConfig, loadEnv } from 'vite'
import react from '@vitejs/plugin-react'
export default defineConfig(({ mode }) => {
// Load all .env vars (no prefix filter) so server-only vars like DEV_API_TARGET
// are available here without being exposed to the browser bundle.
const env = loadEnv(mode, process.cwd(), '')
const base = env.VITE_BASE || '/'
const apiTarget = env.DEV_API_TARGET || 'http://127.0.0.1:3201'
return {
base,
plugins: [react()],
server: {
proxy: {
'/v1': {
target: apiTarget,
changeOrigin: true,
},
},
},
}
})