vite.config.ts 780 B

12345678910111213141516171819202122232425262728293031
  1. import { fileURLToPath, URL } from "node:url";
  2. import { defineConfig, loadEnv } from "vite";
  3. import vue from "@vitejs/plugin-vue";
  4. // https://vitejs.dev/config/
  5. export default defineConfig(({ mode }) => {
  6. //获取各种环境下的对应的变量
  7. let env = loadEnv(mode, process.cwd());
  8. return {
  9. plugins: [vue()],
  10. resolve: {
  11. alias: {
  12. "@": fileURLToPath(new URL("./src", import.meta.url)),
  13. },
  14. },
  15. //代理跨域
  16. server: {
  17. proxy: {
  18. [env.VITE_APP_BASE_API]: {
  19. //获取数据的服务器地址设置
  20. target: env.VITE_SERVE,
  21. //需要代理跨域
  22. changeOrigin: true,
  23. //路径重写
  24. rewrite: (path) => path.replace(/^\/api/, ""),
  25. },
  26. },
  27. },
  28. };
  29. });