37 lines
1.1 KiB
TypeScript
37 lines
1.1 KiB
TypeScript
import { defineConfig } from 'vite'
|
||
import react from '@vitejs/plugin-react'
|
||
|
||
// https://vitejs.dev/config/
|
||
export default defineConfig(({ mode }) => {
|
||
// 获取 API 基础地址(环境变量或默认值)
|
||
// 生产环境默认使用线上地址,开发环境使用本地地址
|
||
// 注意:在 vite.config.ts 中使用 process.env,在代码中使用 import.meta.env
|
||
const apiBaseURL = process.env.VITE_API_BASE_URL ||
|
||
(mode === 'production' ? 'https://admin.duiduiedu.com/admin/v1' : 'http://127.0.0.1:8080/admin/v1')
|
||
|
||
return {
|
||
plugins: [react()],
|
||
resolve: {
|
||
alias: {
|
||
'@': '/src',
|
||
},
|
||
},
|
||
server: {
|
||
host: '0.0.0.0',
|
||
port: 5173,
|
||
proxy: {
|
||
'/admin': {
|
||
target: 'http://127.0.0.1:8080', // 开发环境代理到本地
|
||
changeOrigin: true,
|
||
secure: false, // 忽略 SSL 证书验证
|
||
},
|
||
},
|
||
},
|
||
// 定义全局常量,在代码中可以通过 import.meta.env.VITE_API_BASE_URL 访问
|
||
define: {
|
||
'import.meta.env.VITE_API_BASE_URL': JSON.stringify(apiBaseURL),
|
||
},
|
||
}
|
||
})
|
||
|