vite.config.js 3.6 KB

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