vite.config.js 3.2 KB

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