member-login-management-system/vite.config.js

37 lines
1020 B
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { defineConfig, loadEnv } from 'vite'
import react from '@vitejs/plugin-react'
import path from 'node:path'
// https://vite.dev/config/
export default defineConfig(({ mode }) => {
const env = loadEnv(mode, process.cwd(), '')
// YApi Mock 地址,在 .env.development / .env.development.local 中配置 VITE_YAPI_MOCK
// 例https://yapi.xxx.com/mock/123
const yapiMock = 'http://124.222.159.10:8090'
return {
plugins: [react()],
resolve: {
alias: {
'@': path.resolve(__dirname, 'src'),
},
},
server: {
host: '0.0.0.0',
port: 5173,
proxy: {
// 前端所有 /api 开头的请求都转发到 YApi Mock
// YApi 中接口路径本身带 /api 前缀,无需 rewrite
'/api': {
target: yapiMock,
changeOrigin: true,
secure: false,
// 如后续需去掉 /api 前缀,取消下面这行注释即可
// rewrite: (p) => p.replace(/^\/api/, ''),
},
},
},
}
})