vite.config.js 918 B

12345678910111213141516171819202122232425262728293031323334353637
  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. port: '3001',
  19. host: '0.0.0.0',
  20. proxy: {
  21. '/api': {
  22. ws: true,
  23. changeOrigin: true,
  24. target: getApiUrl(),
  25. rewrite: (path) => path.replace(new RegExp('^/api'), '/'),
  26. }
  27. }
  28. },
  29. })
  30. function getApiUrl() {
  31. const {testApi, baseApi} = website
  32. const url = process.env.NODE_ENV === 'development' ? testApi.api : baseApi.api
  33. console.log('当前请求地址:', url)
  34. return url
  35. }