1
0

vite.config.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import { defineConfig } from 'vite'
  2. import vue from '@vitejs/plugin-vue'
  3. import AutoImport from 'unplugin-auto-import/vite'
  4. import Components from 'unplugin-vue-components/vite'
  5. import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
  6. import path from 'path'
  7. // https://vite.dev/config/
  8. export default defineConfig({
  9. plugins: [
  10. vue(),
  11. AutoImport({
  12. resolvers: [ElementPlusResolver()],
  13. }),
  14. Components({
  15. resolvers: [ElementPlusResolver()],
  16. }),
  17. ],
  18. resolve: {
  19. // 配置路径别名
  20. alias: {
  21. '@': path.resolve(__dirname, 'src'),
  22. 'views': '@/views',
  23. 'assets': '@/assets',
  24. 'common': '@/common',
  25. 'components': '@/components',
  26. 'network': '@/network',
  27. 'router': '@/router',
  28. 'store': '@/store'
  29. },
  30. // 省略文件后缀
  31. extensions: ['', '.js', '.json', '.vue', '.scss', '.css']
  32. },
  33. // 代理配置
  34. server: {
  35. // https: true,
  36. port:3000,
  37. proxy: {
  38. '/api': { // 配置需要代理的路径 --> 这里的意思是代理http://localhost:80/api/后的所有路由
  39. target: 'http://localhost:8888', // 目标地址 --> 服务器地址
  40. changeOrigin: true, // 允许跨域
  41. ws: true, // 允许websocket代理
  42. // 重写路径 --> 作用与vue配置pathRewrite作用相同
  43. rewrite: (path) => path.replace(/^\/api/, "")
  44. }
  45. },
  46. },
  47. })