vite.config.ts 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. import { defineConfig, loadEnv } from "vite";
  2. // import { darkTheme } from "./src/theme.js";
  3. import vue from "@vitejs/plugin-vue";
  4. import Components from "unplugin-vue-components/vite";
  5. import { AntDesignVueResolver } from "unplugin-vue-components/resolvers";
  6. import { visualizer } from "rollup-plugin-visualizer";
  7. import svgLoader from "vite-svg-loader";
  8. import path from "path";
  9. import basicSsl from "@vitejs/plugin-basic-ssl";
  10. // https://vitejs.dev/config/
  11. export default defineConfig(({ mode }) => {
  12. // 第三个参数传空串:不加前缀过滤,才能读到 DMS_TOKEN 这类非 VITE_ 前缀的变量
  13. // (DMS_TOKEN 只写在 .env.development.local,该文件按 .gitignore 不入库)
  14. const env = loadEnv(mode, process.cwd(), "");
  15. return {
  16. plugins: [
  17. vue(),
  18. Components({
  19. resolvers: [AntDesignVueResolver()],
  20. }),
  21. visualizer({
  22. open: false,
  23. gzipSize: true,
  24. file: "./dist/stats.html",
  25. brotliSize: true,
  26. }),
  27. svgLoader(),
  28. basicSsl(),
  29. ],
  30. server: {
  31. proxy: {
  32. //配置本地代理
  33. "/api/": {
  34. //匹配的路径
  35. target: "http://aixq.shqp.gov.cn", //目标url
  36. changeOrigin: true, //跨域
  37. rewrite: (path) => path.replace(/^\/api/, ""), //重写路径
  38. },
  39. // 新版聊天后端代理(POST /api/chat,SSE)
  40. // 开发服务器是 HTTPS 而后端是 HTTP,浏览器会拦截直连(混合内容),
  41. // 且后端未实现 CORS,因此开发环境统一走同源代理。
  42. // 对应 .env.development 中 VITE_CHAT_API="/chat-api"
  43. // target 取 VITE_CHAT_TARGET(地址收在 env 里,不再写死在配置文件中)
  44. "/chat-api/": {
  45. target: env.VITE_CHAT_TARGET || "http://192.168.2.23:8000",
  46. changeOrigin: true,
  47. rewrite: (path) => path.replace(/^\/chat-api/, ""),
  48. },
  49. // DMS 数据管理服务(会话/问答记录/反馈)
  50. // 两件事都在代理侧做,浏览器拿不到:
  51. // ① 补回 /dms 前缀(DMS 的真实路由都在 /dms/ 下)
  52. // ② 注入 token 头(DMS 的鉴权头名就叫 token,不是 Authorization)
  53. // token 来源:.env.development.local 的 DMS_TOKEN(不入库)
  54. "/dms-api/": {
  55. target: env.VITE_DMS_TARGET || "http://121.43.55.7:10081",
  56. changeOrigin: true,
  57. rewrite: (path) => path.replace(/^\/dms-api/, "/dms"),
  58. headers: env.DMS_TOKEN ? { token: env.DMS_TOKEN } : {},
  59. },
  60. "/asr/": {
  61. //匹配的路径
  62. target: "https://human-screen-v3.metamaker.cn", //目标url
  63. changeOrigin: true, //跨域
  64. rewrite: (path) => path.replace(/^\/asr/, ""), //重写路径
  65. ws: true,
  66. },
  67. // [已移除] "/stream/" 代理(数字人视频流):src/index.html 里没有任何代码往它发请求,
  68. // 相关 env(VITE_STREAM_SERVER / VITE_STREAM_TOKEN / VITE_HUMAN_IDLE_MP4_URL)也已删除。
  69. // 注意 "/asr/" 代理**保留** —— 它是切到讯飞 ASR 分支(VITE_XF_ASR="/asr")的退路。
  70. },
  71. },
  72. build: {
  73. rollupOptions: {
  74. input: {
  75. main: path.resolve(__dirname, "index.html"),
  76. redirect: path.resolve(__dirname, "redirect.html"),
  77. },
  78. output: {
  79. manualChunks: (id) => {
  80. console.log(id);
  81. if (id.includes("node_modules/three")) {
  82. return "three";
  83. } else if (id.includes("node_modules")) {
  84. return "vendor";
  85. }
  86. },
  87. },
  88. },
  89. assetsInlineLimit: 20480,
  90. },
  91. resolve: {
  92. alias: {
  93. "@": path.resolve("./src/"),
  94. three$: path.resolve(__dirname, "./node_modules/three/build/three.cjs"),
  95. },
  96. },
  97. base: "./",
  98. css: {
  99. preprocessorOptions: {
  100. scss: {
  101. api: "modern-compiler",
  102. },
  103. },
  104. },
  105. };
  106. });