vite.config.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. import { defineConfig, loadEnv } from 'vite'
  2. import path from 'path'
  3. import createVitePlugins from './vite/plugins'
  4. // https://vitejs.dev/config/
  5. export default defineConfig(({ mode, command }) => {
  6. const env = loadEnv(mode, process.cwd())
  7. const { VITE_APP_ENV } = env
  8. return {
  9. // 部署生产环境和开发环境下的URL。
  10. // 默认情况下,vite 会假设你的应用是被部署在一个域名的根路径上
  11. // 例如 https://www.ezhizao.cn/。如果应用被部署在一个子路径上,你就需要用这个选项指定这个子路径。例如,如果你的应用被部署在 https://www.ezhizao.cn/admin/,则设置 baseUrl 为 /admin/。
  12. base: VITE_APP_ENV === 'production' ? '/' : '/',
  13. plugins: createVitePlugins(env, command === 'build'),
  14. resolve: {
  15. // https://cn.vitejs.dev/config/#resolve-alias
  16. alias: {
  17. // 设置路径
  18. '~': path.resolve(__dirname, './'),
  19. // 设置别名
  20. '@': path.resolve(__dirname, './src')
  21. },
  22. // https://cn.vitejs.dev/config/#resolve-extensions
  23. extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json', '.vue']
  24. },
  25. // vite 相关配置
  26. server: {
  27. port: 81,
  28. host: true,
  29. open: true,
  30. proxy: {
  31. // https://cn.vitejs.dev/config/#server-proxy
  32. '/dev-api': {
  33. target: 'http://localhost:8040',
  34. changeOrigin: true,
  35. rewrite: (p) => p.replace(/^\/dev-api/, '')
  36. },
  37. '/test-api': {
  38. target: 'http://localhost:8040',
  39. changeOrigin: true,
  40. rewrite: (p) => p.replace(/^\/test-api/, '')
  41. },
  42. '/ezhizao-yzbh-sys': {
  43. target: 'http://localhost:8040',
  44. changeOrigin: true,
  45. rewrite: (p) => p.replace(/^\/ezhizao-yzbh-sys/, '')
  46. },
  47. // 客户管理配置示例
  48. '/ezhizao-yzbh-crm': {
  49. target: 'http://localhost:8041',
  50. changeOrigin: true,
  51. rewrite: (p) => p.replace(/^\/ezhizao-yzbh-crm/, '')
  52. },
  53. // 委托管理配置示例
  54. '/ezhizao-yzbh-entrust': {
  55. target: 'http://localhost:8042',
  56. changeOrigin: true,
  57. rewrite: (p) => p.replace(/^\/ezhizao-yzbh-entrust/, '')
  58. },
  59. // 税务管理配置示例
  60. '/ezhizao-yzbh-finance': {
  61. target: 'http://localhost:8043',
  62. changeOrigin: true,
  63. rewrite: (p) => p.replace(/^\/ezhizao-yzbh-finance/, '')
  64. },
  65. // 生产管理配置示例
  66. '/ezhizao-yzbh-production': {
  67. target: 'http://localhost:8043',
  68. changeOrigin: true,
  69. rewrite: (p) => p.replace(/^\/ezhizao-yzbh-production/, '')
  70. },
  71. // 财务管理配置示例
  72. '/ezhizao-yzbh-financial': {
  73. target: 'http://localhost:8044',
  74. changeOrigin: true,
  75. rewrite: (p) => p.replace(/^\/ezhizao-yzbh-financial/, '')
  76. }
  77. }
  78. },
  79. //fix:error:stdin>:7356:1: warning: "@charset" must be the first rule in the file
  80. css: {
  81. postcss: {
  82. plugins: [
  83. {
  84. postcssPlugin: 'internal:charset-removal',
  85. AtRule: {
  86. charset: (atRule) => {
  87. if (atRule.name === 'charset') {
  88. atRule.remove();
  89. }
  90. }
  91. }
  92. }
  93. ]
  94. }
  95. }
  96. }
  97. })