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,
        port: '3001',
        host: '0.0.0.0',
        proxy: {
            '/api': {
                ws: true,
                changeOrigin: true,
                target: getApiUrl(),
                rewrite: (path) => path.replace(new RegExp('^/api'), '/'),
            }
        }
    },
})

function getApiUrl() {
    const {testApi, baseApi} = website
    const url = process.env.NODE_ENV === 'development' ? testApi.api : baseApi.api
    console.log('当前请求地址：', url)
    return url
}
