chore: 工程底座(Vite + Vue 3 + TS + TDesign + vue-query + Pinia + VueUse + Vitest)

vite dev server 代理 /api、/v1 到 GATEWAY(仅从环境变量读取,.env.example 提供示例,代码不写死默认值,dev 未配置时报错);oxlint + eslint + prettier;vitest 含 jsdom 组件测试环境。
This commit is contained in:
2026-09-08 00:49:19 +08:00
parent b2e0aa4a6c
commit c3d6f379f9
18 changed files with 1197 additions and 0 deletions
+38
View File
@@ -0,0 +1,38 @@
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,
},
};
});