vite.config.ts 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. import { defineConfig } from 'vite'
  2. import vue from '@vitejs/plugin-vue'
  3. import { resolve } from 'path'
  4. import { OUTPUT_DIR, brotliSize, chunkSizeWarningLimit, terserOptions, rollupOptions } from './build/constant'
  5. import viteCompression from 'vite-plugin-compression'
  6. import { viteMockServe } from 'vite-plugin-mock'
  7. import monacoEditorPlugin from 'vite-plugin-monaco-editor'
  8. function pathResolve(dir: string) {
  9. return resolve(process.cwd(), '.', dir)
  10. }
  11. export default defineConfig({
  12. base: '/forge-report',
  13. // 修改端口
  14. server: {
  15. port: 3021,
  16. open: true,
  17. proxy: {
  18. // forge-report 后端接口(项目管理、AI 供应商、AI Agent、AI 对话)
  19. '/forge-report-api': {
  20. target: 'http://localhost:8581',
  21. changeOrigin: true,
  22. rewrite: (path: string) => path.replace(/^\/forge-report-api/, '/')
  23. },
  24. // LLM API 代理(阿里百炼 OpenAI 兼容接口,保留用于前端直调模式)
  25. '/llm': {
  26. target: 'https://dashscope.aliyuncs.com',
  27. changeOrigin: true,
  28. rewrite: (path: string) => path.replace(/^\/llm/, '/compatible-mode'),
  29. // SSE 流式代理:禁用上游 gzip 压缩以避免缓冲全量响应
  30. configure: (proxy) => {
  31. proxy.on('proxyReq', (proxyReq) => {
  32. proxyReq.setHeader('Accept-Encoding', 'identity')
  33. })
  34. }
  35. }
  36. }
  37. },
  38. // 路径重定向
  39. resolve: {
  40. alias: [
  41. {
  42. find: /\/#\//,
  43. replacement: pathResolve('types')
  44. },
  45. {
  46. find: '@',
  47. replacement: pathResolve('src')
  48. },
  49. {
  50. find: 'vue-i18n',
  51. replacement: 'vue-i18n/dist/vue-i18n.cjs.js' //解决i8n警告
  52. }
  53. ],
  54. dedupe: ['vue']
  55. },
  56. // 全局 css 注册
  57. css: {
  58. preprocessorOptions: {
  59. scss: {
  60. javascriptEnabled: true,
  61. additionalData: `@import "src/styles/common/style.scss";`
  62. }
  63. }
  64. },
  65. define: {
  66. // enable hydration mismatch details in production build
  67. __VUE_PROD_HYDRATION_MISMATCH_DETAILS__: 'true'
  68. },
  69. plugins: [
  70. vue({
  71. template: {
  72. compilerOptions: {
  73. // 排除 iconify 图标影子组件编译报错
  74. isCustomElement: tag => tag.startsWith('iconify-icon')
  75. }
  76. }
  77. }),
  78. monacoEditorPlugin({
  79. languageWorkers: ['editorWorkerService', 'typescript', 'json', 'html']
  80. }),
  81. viteMockServe({
  82. mockPath: '/src/api/mock',
  83. // 开发打包开关
  84. localEnabled: true,
  85. // 生产打包开关
  86. prodEnabled: true,
  87. // 打开后,可以读取 ts 文件模块。 请注意,打开后将无法监视.js 文件
  88. supportTs: true,
  89. // 监视文件更改
  90. watchFiles: true
  91. }),
  92. // 压缩
  93. viteCompression({
  94. verbose: true,
  95. disable: false,
  96. threshold: 10240,
  97. algorithm: 'gzip',
  98. ext: '.gz'
  99. })
  100. ],
  101. build: {
  102. target: 'es2020',
  103. outDir: OUTPUT_DIR,
  104. // minify: 'terser', // 如果需要用terser混淆,可打开这两行
  105. // terserOptions: terserOptions,
  106. rollupOptions: rollupOptions,
  107. reportCompressedSize: brotliSize,
  108. chunkSizeWarningLimit: chunkSizeWarningLimit
  109. }
  110. })