vite.config.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import { defineConfig, loadEnv } from 'vite'
  2. import vue from '@vitejs/plugin-vue'
  3. import vueJsx from '@vitejs/plugin-vue-jsx'
  4. import path from 'path'
  5. import { fileURLToPath } from 'url'
  6. const __dirname = path.dirname(fileURLToPath(import.meta.url))
  7. function resolve(dir) {
  8. return path.join(__dirname, dir)
  9. }
  10. export default defineConfig(({ command, mode }) => {
  11. // 加载env文件
  12. const env = loadEnv(mode, process.cwd(), '')
  13. return {
  14. plugins: [
  15. vue(),
  16. vueJsx()
  17. ],
  18. resolve: {
  19. alias: {
  20. '@': resolve('src'),
  21. '@api': resolve('src/api'),
  22. '@assets': resolve('src/assets'),
  23. '@layouts': resolve('src/layouts'),
  24. '@static': resolve('src/static'),
  25. '@components': resolve('src/components'),
  26. '@router': resolve('src/router'),
  27. '@utils': resolve('src/utils'),
  28. '@store': resolve('src/store'),
  29. '@views': resolve('src/views')
  30. },
  31. extensions: ['.js', '.jsx', '.ts', '.tsx', '.json', '.vue']
  32. },
  33. server: {
  34. port: 8003,
  35. proxy: {
  36. '/WebSocketConfig/': {
  37. target: 'ws://test.com',
  38. changeOrigin: true,
  39. ws: true,
  40. },
  41. '/api/': {
  42. target: 'http://test.com',
  43. changeOrigin: true,
  44. ws: false,
  45. }
  46. }
  47. },
  48. base: '/',
  49. }
  50. })