import { fileURLToPath, URL } from 'node:url'; import vue from '@vitejs/plugin-vue'; import vueJsx from '@vitejs/plugin-vue-jsx'; import vueDevTools from 'vite-plugin-vue-devtools'; import { defineConfig, loadEnv } from 'vite'; // NewAPI 网关地址只从环境变量 GATEWAY 读取(.env.local / shell 均可),代码不写死默认值—— // 换网关/换部署目标改配置即可,仓库里不出现具体网关地址。 // 页面所有接口请求打相对路径(/api、/v1),由 dev server 代理转发到网关,绕开 CORS 限制。 // 未配置时 dev 启动直接失败(build 无代理不受影响)。 export default defineConfig(({ mode }) => { const env = loadEnv(mode, process.cwd(), ''); const gateway = env.GATEWAY?.trim(); if (mode === 'development' && !gateway) { throw new Error( '[bench] 未配置网关地址:请设置环境变量 GATEWAY(或在 new-api-key-bench/.env.local 写 GATEWAY=https://…)', ); } return { plugins: [vue(), vueJsx(), vueDevTools()], resolve: { alias: { '@': fileURLToPath(new URL('./src', import.meta.url)), }, }, server: { proxy: gateway ? { '/api': { target: gateway, changeOrigin: true }, '/v1': { target: gateway, changeOrigin: true }, } : undefined, }, }; });