vite.config.ts 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. "/chat-api/": {
  44. target: "http://192.168.2.23:8000",
  45. changeOrigin: true,
  46. rewrite: (path) => path.replace(/^\/chat-api/, ""),
  47. },
  48. // DMS 数据管理服务(会话/问答记录/反馈)
  49. // 两件事都在代理侧做,浏览器拿不到:
  50. // ① 补回 /dms 前缀(DMS 的真实路由都在 /dms/ 下)
  51. // ② 注入 token 头(DMS 的鉴权头名就叫 token,不是 Authorization)
  52. // token 来源:.env.development.local 的 DMS_TOKEN(不入库)
  53. "/dms-api/": {
  54. target: env.VITE_DMS_TARGET || "http://121.43.55.7:10081",
  55. changeOrigin: true,
  56. rewrite: (path) => path.replace(/^\/dms-api/, "/dms"),
  57. headers: env.DMS_TOKEN ? { token: env.DMS_TOKEN } : {},
  58. },
  59. "/asr/": {
  60. //匹配的路径
  61. target: "https://human-screen-v3.metamaker.cn", //目标url
  62. changeOrigin: true, //跨域
  63. rewrite: (path) => path.replace(/^\/asr/, ""), //重写路径
  64. ws: true,
  65. },
  66. "/stream/": {
  67. //匹配的路径
  68. target: "https://flv-enc.metamaker.cn", //目标url
  69. changeOrigin: true, //跨域
  70. rewrite: (path) => path.replace(/^\/stream/, ""), //重写路径
  71. ws: true,
  72. headers: {
  73. Connection: "keep-alive",
  74. },
  75. },
  76. },
  77. },
  78. build: {
  79. rollupOptions: {
  80. input: {
  81. main: path.resolve(__dirname, "index.html"),
  82. redirect: path.resolve(__dirname, "redirect.html"),
  83. },
  84. output: {
  85. manualChunks: (id) => {
  86. console.log(id);
  87. if (id.includes("node_modules/three")) {
  88. return "three";
  89. } else if (id.includes("node_modules")) {
  90. return "vendor";
  91. }
  92. },
  93. },
  94. },
  95. assetsInlineLimit: 20480,
  96. },
  97. resolve: {
  98. alias: {
  99. "@": path.resolve("./src/"),
  100. three$: path.resolve(__dirname, "./node_modules/three/build/three.cjs"),
  101. },
  102. },
  103. base: "./",
  104. css: {
  105. preprocessorOptions: {
  106. scss: {
  107. api: "modern-compiler",
  108. },
  109. },
  110. },
  111. };
  112. });