vite.config.js 840 B

12345678910111213141516171819202122232425262728293031323334
  1. import {defineConfig} from 'vite'
  2. import uni from "@dcloudio/vite-plugin-uni";
  3. import Unocss from 'unocss/vite'
  4. import {resolve} from "path";
  5. import website from './config/index';
  6. export default defineConfig({
  7. resolve: {
  8. alias: {
  9. '~api': resolve(__dirname, './httpApi/modules'),
  10. }
  11. },
  12. plugins: [
  13. uni(),
  14. Unocss(),
  15. ],
  16. server: {
  17. ...website.vite,
  18. proxy: {
  19. '/api': {
  20. ws: true,
  21. changeOrigin: true,
  22. target: getApiUrl(),
  23. rewrite: (path) => path.replace(new RegExp('^/api'), '/'),
  24. }
  25. }
  26. },
  27. })
  28. function getApiUrl() {
  29. const url = process.env.NODE_ENV === 'development' ? website.testApi : website.baseApi
  30. console.log('当前请求地址:', url)
  31. return url
  32. }