nex_animation/frontend/vite.config.ts

32 lines
1.5 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import tailwindcss from '@tailwindcss/vite'
declare const process: { env: Record<string, string | undefined> }
/* 配置文件本身以 ESM 加载,import.meta.url 就够用,不必为此装 @types/node */
// 开发态把 /api 与 /media 代理到本地 FastAPI(默认 127.0.0.1:8000)
const backend = process.env.NEX_BACKEND || 'http://127.0.0.1:8000'
export default defineConfig({
plugins: [react(), tailwindcss()],
// '@' → src:标准控件组(shadcn)的组件源码一律 import '@/lib/utils'、'@/components/kit',
// 别名和 tsconfig.json 的 paths 必须一致,否则 npx shadcn add 下来的文件跑不起来。
resolve: { alias: { '@': new URL('./src', import.meta.url).pathname } },
server: {
host: '0.0.0.0',
port: 5173,
// 局域网访问:IP 默认放行,但 macOS 的 mDNS 机器名(http://xxx.local:5173)会被
// Vite 的 Host 校验拦成 403「Blocked request」。只放行 .local 后缀,任意域名仍拦住。
allowedHosts: ['.local'],
proxy: {
'/api': { target: backend, changeOrigin: true },
'/health': { target: backend, changeOrigin: true },
'/media': { target: backend, changeOrigin: true },
'/docs': { target: backend, changeOrigin: true },
'/openapi.json': { target: backend, changeOrigin: true }
}
},
build: { outDir: 'dist', emptyOutDir: true, chunkSizeWarningLimit: 1200 }
})