vite.config.ts 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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 { VantResolver } from "@vant/auto-import-resolver";
  6. import { fileURLToPath, URL } from "node:url";
  7. export default defineConfig({
  8. plugins: [
  9. vue(),
  10. AutoImport({
  11. resolvers: [VantResolver()],
  12. }),
  13. Components({
  14. resolvers: [VantResolver()],
  15. }),
  16. ],
  17. resolve: {
  18. alias: {
  19. "@": fileURLToPath(new URL("./src", import.meta.url)),
  20. },
  21. extensions: [".mjs", ".js", ".ts", ".jsx", ".tsx", ".json", ".vue"],
  22. },
  23. server: {
  24. //方式二:设置多个代理
  25. proxy: {
  26. //这个路径为http://192.168.1.182:3000/douyu/wgapi/vod/front/vodrank/getTagVideos
  27. "/ucenter": {
  28. //target是代理的目标路径
  29. target: "https://v4-uat.4dkankan.com",
  30. changeOrigin: true, //必须要开启跨域
  31. //pathRewrite重写请求的路径,实际请求的路径没有代理标识douyu,需要把斗鱼重置为空字符串
  32. rewrite: (path) => path.replace(/\/ucenter/, ""), // 路径重写
  33. },
  34. "/service": {
  35. //target是代理的目标路径
  36. target: "https://v4-uat.4dkankan.com",
  37. changeOrigin: true, //必须要开启跨域
  38. //pathRewrite重写请求的路径,实际请求的路径没有代理标识douyu,需要把斗鱼重置为空字符串
  39. rewrite: (path) => path.replace(/\/service/, ""), // 路径重写
  40. },
  41. },
  42. },
  43. });