vite.config.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. import { createRequire } from 'node:module'
  2. const require = createRequire(import.meta.url)
  3. const uniPlugin = require('@dcloudio/vite-plugin-uni')
  4. import { defineConfig, loadEnv } from 'vite'
  5. import Unocss from 'unocss/vite'
  6. import AutoImport from 'unplugin-auto-import/vite'
  7. import Components from 'unplugin-vue-components/vite'
  8. import path from 'node:path'
  9. import { pluginIcons, pluginPagePathes } from './build/plugin-isme/index.js'
  10. const uni = uniPlugin.default
  11. export default defineConfig(({ mode }) => {
  12. const viteEnv = loadEnv(mode, process.cwd())
  13. const { VITE_HTTP_PORT, VITE_REQUEST_PREFIX, VITE_PUBLIC_PATH, VITE_HTTP_PROXY_TARGET, VITE_FLOW_PROXY_TARGET } = viteEnv
  14. const requestPrefix = VITE_REQUEST_PREFIX || '/dev-api'
  15. const proxyTarget = VITE_HTTP_PROXY_TARGET || 'http://127.0.0.1:8581/'
  16. const flowProxyTarget = VITE_FLOW_PROXY_TARGET || proxyTarget
  17. return {
  18. base: VITE_PUBLIC_PATH || '/',
  19. plugins: [
  20. uni(),
  21. Unocss(),
  22. AutoImport({
  23. imports: ['vue'],
  24. dts: false,
  25. }),
  26. Components({
  27. dts: false,
  28. }),
  29. pluginPagePathes(),
  30. pluginIcons(),
  31. ],
  32. resolve: {
  33. alias: {
  34. '@': path.resolve(process.cwd(), 'src'),
  35. '~': path.resolve(process.cwd()),
  36. },
  37. },
  38. define: {
  39. global: 'window',
  40. },
  41. css: {
  42. preprocessorOptions: {
  43. scss: {
  44. additionalData: `@import "@/styles/variables.scss";`,
  45. silenceDeprecations: ['legacy-js-api', 'color-functions', 'import'],
  46. },
  47. },
  48. },
  49. server: {
  50. port: VITE_HTTP_PORT || 3009,
  51. open: false,
  52. host: '0.0.0.0',
  53. proxy: {
  54. // Flowable 流程服务代理:待办、审批、流程历史等接口默认走独立 flow-server。
  55. [`${requestPrefix}/api/flow`]: {
  56. target: flowProxyTarget,
  57. changeOrigin: true,
  58. secure: false,
  59. rewrite: path => path.replace(new RegExp(`^${requestPrefix}`), ''),
  60. configure: (proxy, options) => {
  61. proxy.on('proxyRes', (proxyRes, req) => {
  62. proxyRes.headers['x-real-url'] = new URL(req.url || '', options.target)?.href || ''
  63. })
  64. },
  65. },
  66. // 业务待办表单/动作由 flow-server 内的 BusinessFlowController 提供。
  67. // 该规则必须在通用 app-server 代理之前,否则会被转发到 8583 并返回 404。
  68. [`${requestPrefix}/ai/business/flow`]: {
  69. target: flowProxyTarget,
  70. changeOrigin: true,
  71. secure: false,
  72. rewrite: path => path.replace(new RegExp(`^${requestPrefix}`), ''),
  73. configure: (proxy, options) => {
  74. proxy.on('proxyRes', (proxyRes, req) => {
  75. proxyRes.headers['x-real-url'] = new URL(req.url || '', options.target)?.href || ''
  76. })
  77. },
  78. },
  79. // Forge App 服务代理:H5 登录、用户信息、验证码等基础接口默认走 app-server。
  80. [requestPrefix]: {
  81. target: proxyTarget,
  82. changeOrigin: true,
  83. secure: false,
  84. rewrite: path => path.replace(new RegExp(`^${requestPrefix}`), ''),
  85. configure: (proxy, options) => {
  86. proxy.on('proxyRes', (proxyRes, req) => {
  87. proxyRes.headers['x-real-url'] = new URL(req.url || '', options.target)?.href || ''
  88. })
  89. },
  90. },
  91. // WebSocket
  92. '/ws': {
  93. target: proxyTarget,
  94. changeOrigin: true,
  95. ws: true,
  96. secure: false,
  97. },
  98. },
  99. },
  100. build: {
  101. chunkSizeWarningLimit: 1024,
  102. },
  103. }
  104. })