| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- import { defineConfig, loadEnv } from "vite";
- // import { darkTheme } from "./src/theme.js";
- import vue from "@vitejs/plugin-vue";
- import Components from "unplugin-vue-components/vite";
- import { AntDesignVueResolver } from "unplugin-vue-components/resolvers";
- import { visualizer } from "rollup-plugin-visualizer";
- import svgLoader from "vite-svg-loader";
- import path from "path";
- import basicSsl from "@vitejs/plugin-basic-ssl";
- // https://vitejs.dev/config/
- export default defineConfig(({ mode }) => {
- // 第三个参数传空串:不加前缀过滤,才能读到 DMS_TOKEN 这类非 VITE_ 前缀的变量
- // (DMS_TOKEN 只写在 .env.development.local,该文件按 .gitignore 不入库)
- const env = loadEnv(mode, process.cwd(), "");
- return {
- plugins: [
- vue(),
- Components({
- resolvers: [AntDesignVueResolver()],
- }),
- visualizer({
- open: false,
- gzipSize: true,
- file: "./dist/stats.html",
- brotliSize: true,
- }),
- svgLoader(),
- basicSsl(),
- ],
- server: {
- proxy: {
- //配置本地代理
- "/api/": {
- //匹配的路径
- target: "http://aixq.shqp.gov.cn", //目标url
- changeOrigin: true, //跨域
- rewrite: (path) => path.replace(/^\/api/, ""), //重写路径
- },
- // 新版聊天后端代理(POST /api/chat,SSE)
- // 开发服务器是 HTTPS 而后端是 HTTP,浏览器会拦截直连(混合内容),
- // 且后端未实现 CORS,因此开发环境统一走同源代理。
- // 对应 .env.development 中 VITE_CHAT_API="/chat-api"
- // target 取 VITE_CHAT_TARGET(地址收在 env 里,不再写死在配置文件中)
- "/chat-api/": {
- target: env.VITE_CHAT_TARGET || "http://192.168.2.23:8000",
- changeOrigin: true,
- rewrite: (path) => path.replace(/^\/chat-api/, ""),
- },
- // DMS 数据管理服务(会话/问答记录/反馈)
- // 两件事都在代理侧做,浏览器拿不到:
- // ① 补回 /dms 前缀(DMS 的真实路由都在 /dms/ 下)
- // ② 注入 token 头(DMS 的鉴权头名就叫 token,不是 Authorization)
- // token 来源:.env.development.local 的 DMS_TOKEN(不入库)
- "/dms-api/": {
- target: env.VITE_DMS_TARGET || "http://121.43.55.7:10081",
- changeOrigin: true,
- rewrite: (path) => path.replace(/^\/dms-api/, "/dms"),
- headers: env.DMS_TOKEN ? { token: env.DMS_TOKEN } : {},
- },
- "/asr/": {
- //匹配的路径
- target: "https://human-screen-v3.metamaker.cn", //目标url
- changeOrigin: true, //跨域
- rewrite: (path) => path.replace(/^\/asr/, ""), //重写路径
- ws: true,
- },
- // [已移除] "/stream/" 代理(数字人视频流):src/index.html 里没有任何代码往它发请求,
- // 相关 env(VITE_STREAM_SERVER / VITE_STREAM_TOKEN / VITE_HUMAN_IDLE_MP4_URL)也已删除。
- // 注意 "/asr/" 代理**保留** —— 它是切到讯飞 ASR 分支(VITE_XF_ASR="/asr")的退路。
- },
- },
- build: {
- rollupOptions: {
- input: {
- main: path.resolve(__dirname, "index.html"),
- redirect: path.resolve(__dirname, "redirect.html"),
- },
- output: {
- manualChunks: (id) => {
- console.log(id);
- if (id.includes("node_modules/three")) {
- return "three";
- } else if (id.includes("node_modules")) {
- return "vendor";
- }
- },
- },
- },
- assetsInlineLimit: 20480,
- },
- resolve: {
- alias: {
- "@": path.resolve("./src/"),
- three$: path.resolve(__dirname, "./node_modules/three/build/three.cjs"),
- },
- },
- base: "./",
- css: {
- preprocessorOptions: {
- scss: {
- api: "modern-compiler",
- },
- },
- },
- };
- });
|