vite.config.ts 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. import react from "@vitejs/plugin-react-swc";
  2. import { visualizer } from "rollup-plugin-visualizer";
  3. import { defineConfig } from "vite";
  4. import { createHtmlPlugin } from 'vite-plugin-html';
  5. import { viteStaticCopy } from 'vite-plugin-static-copy';
  6. import svgr from "vite-plugin-svgr";
  7. const apiRoutes = ["^/api/", "/health"];
  8. import path from "path";
  9. // Use environment variable to determine the target.
  10. // const target = process.env.VITE_PROXY_TARGET || "http://localhost:7860";
  11. // const target = process.env.VITE_PROXY_TARGET || "http://npcall.ai:3101";
  12. const target = process.env.VITE_PROXY_TARGET || "http://dev.npcall.ai:3201";
  13. const proxyTargets = apiRoutes.reduce((proxyObj, route) => {
  14. proxyObj[route] = {
  15. target: target,
  16. changeOrigin: true,
  17. secure: false,
  18. ws: true,
  19. };
  20. // 文件服务地址
  21. proxyObj['/bisheng'] = {
  22. target: "http://npcal.ai:8402",
  23. changeOrigin: true,
  24. withCredentials: true,
  25. secure: false
  26. }
  27. return proxyObj;
  28. }, {});
  29. const app_env = { BASE_URL: '' }
  30. export default defineConfig(() => {
  31. return {
  32. base: app_env.BASE_URL || '/',
  33. build: {
  34. outDir: "build",
  35. rollupOptions: {
  36. output: {
  37. manualChunks: {
  38. acebuilds: ['react-ace', 'ace-builds', 'react-syntax-highlighter', 'rehype-mathjax', 'react-markdown'],
  39. reactflow: ['reactflow'],
  40. pdfjs: ['pdfjs-dist'],
  41. reactdrop: ['react-window', 'react-beautiful-dnd', 'react-dropzone']
  42. }
  43. }
  44. }
  45. },
  46. resolve: {
  47. alias: {
  48. '@': path.resolve(__dirname, './src')
  49. }
  50. },
  51. plugins: [
  52. react(),
  53. svgr(),
  54. createHtmlPlugin({
  55. minify: true,
  56. inject: {
  57. data: {
  58. aceScriptSrc: `<script src="${process.env.NODE_ENV === 'production' ? app_env.BASE_URL : ''}/node_modules/ace-builds/src-min-noconflict/ace.js" type="text/javascript"></script>`,
  59. },
  60. },
  61. }),
  62. viteStaticCopy({
  63. targets: [
  64. {
  65. src: [
  66. 'node_modules/ace-builds/src-min-noconflict/ace.js',
  67. 'node_modules/ace-builds/src-min-noconflict/mode-json.js',
  68. 'node_modules/ace-builds/src-min-noconflict/worker-json.js',
  69. 'node_modules/ace-builds/src-min-noconflict/mode-yaml.js',
  70. 'node_modules/ace-builds/src-min-noconflict/worker-yaml.js'
  71. ],
  72. dest: 'node_modules/ace-builds/src-min-noconflict/'
  73. },
  74. {
  75. src: 'node_modules/pdfjs-dist/build/pdf.worker.min.js',
  76. dest: './'
  77. }
  78. ]
  79. }),
  80. // 打包物体积报告
  81. // visualizer({
  82. // open: true,
  83. // })
  84. ],
  85. define: {
  86. __APP_ENV__: JSON.stringify(app_env)
  87. },
  88. server: {
  89. host: '0.0.0.0',
  90. port: 3001,
  91. proxy: {
  92. ...proxyTargets,
  93. },
  94. },
  95. };
  96. });