import {defineConfig} from 'vite' import uni from "@dcloudio/vite-plugin-uni"; import Unocss from 'unocss/vite' import {resolve} from "path"; import website from './config/index'; export default defineConfig({ resolve: { alias: { '~api': resolve(__dirname, './httpApi/modules'), } }, plugins: [ uni(), Unocss(), ], server: { ...website.vite, proxy: { '/api': { ws: true, changeOrigin: true, target: getApiUrl(), rewrite: (path) => path.replace(new RegExp('^/api'), '/'), } } }, }) function getApiUrl() { const url = process.env.NODE_ENV === 'development' ? website.testApi : website.baseApi console.log('当前请求地址:', url) return url }