vite.config.js 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. '/ezhizao-dms-sys': {
  33. target: 'http://localhost:8080',
  34. changeOrigin: true,
  35. rewrite: (p) => p.replace(/^\/ezhizao-dms-sys/, '')
  36. },
  37. // 生产管理配置示例
  38. '/ezhizao-dms-production': {
  39. target: 'http://localhost:8081',
  40. changeOrigin: true,
  41. rewrite: (p) => p.replace(/^\/ezhizao-dms-production/, '')
  42. },
  43. // 生产报工配置
  44. '/ezhizao-dms-p2': {
  45. target: 'http://localhost:8098',
  46. changeOrigin: true,
  47. rewrite: (p) => p.replace(/^\/ezhizao-dms-p2/, '')
  48. },
  49. '/ws-sys': {
  50. target: 'ws://localhost:8080/wsMessage',
  51. changeOrigin: true,
  52. rewrite: (p) => p.replace(/^\/ws-sys/, ''),
  53. ws: true
  54. },
  55. '/ws-production': {
  56. target: 'ws://localhost:8080/wsExport',
  57. changeOrigin: true,
  58. rewrite: (p) => p.replace(/^\/ws-production/, ''),
  59. ws: true
  60. },
  61. '/ezhizao-dms-jd': {
  62. target: 'http://localhost:8083',
  63. changeOrigin: true,
  64. rewrite: (p) => p.replace(/^\/ezhizao-dms-jd/, '')
  65. }
  66. }
  67. },
  68. //fix:error:stdin>:7356:1: warning: "@charset" must be the first rule in the file
  69. css: {
  70. postcss: {
  71. plugins: [
  72. {
  73. postcssPlugin: 'internal:charset-removal',
  74. AtRule: {
  75. charset: (atRule) => {
  76. if (atRule.name === 'charset') {
  77. atRule.remove()
  78. }
  79. }
  80. }
  81. }
  82. ]
  83. }
  84. },
  85. esbuild: {
  86. jsxFactory: 'h',
  87. jsxFragment: 'Fragment',
  88. // jsxInject: `import { h } from 'vue';`,
  89. }
  90. }
  91. })