vite.config.ts 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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/": {
  68. //匹配的路径
  69. target: "https://flv-enc.metamaker.cn", //目标url
  70. changeOrigin: true, //跨域
  71. rewrite: (path) => path.replace(/^\/stream/, ""), //重写路径
  72. ws: true,
  73. headers: {
  74. Connection: "keep-alive",
  75. },
  76. },
  77. },
  78. },
  79. build: {
  80. rollupOptions: {
  81. input: {
  82. main: path.resolve(__dirname, "index.html"),
  83. redirect: path.resolve(__dirname, "redirect.html"),
  84. },
  85. output: {
  86. manualChunks: (id) => {
  87. console.log(id);
  88. if (id.includes("node_modules/three")) {
  89. return "three";
  90. } else if (id.includes("node_modules")) {
  91. return "vendor";
  92. }
  93. },
  94. },
  95. },
  96. assetsInlineLimit: 20480,
  97. },
  98. resolve: {
  99. alias: {
  100. "@": path.resolve("./src/"),
  101. three$: path.resolve(__dirname, "./node_modules/three/build/three.cjs"),
  102. },
  103. },
  104. base: "./",
  105. css: {
  106. preprocessorOptions: {
  107. scss: {
  108. api: "modern-compiler",
  109. },
  110. },
  111. },
  112. };
  113. });