vite.config.ts 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import { defineConfig } from "vite";
  2. import react from "@vitejs/plugin-react";
  3. import path from "path";
  4. export default defineConfig(() => {
  5. // 加载环境变量
  6. return {
  7. plugins: [react()],
  8. base: '/spaces/', // ← 必须加这一行
  9. // 路径别名
  10. resolve: {
  11. alias: {
  12. "@": path.resolve(__dirname, "./src"),
  13. },
  14. },
  15. // 开发服务器配置
  16. server: {
  17. port: 3000,
  18. host: true, // 监听所有地址
  19. open: false, // 自动打开浏览器
  20. // 代理配置
  21. proxy: {
  22. // 代理所有 /sohoyw-som 开头的请求
  23. "/sohoyw-som": {
  24. target: "http://52.83.132.95:8080",
  25. changeOrigin: true,
  26. // configure: (proxy) => {
  27. // proxy.on("proxyReq", (proxyReq) => {
  28. // // 添加模拟登录的 Cookie
  29. // proxyReq.setHeader(
  30. // "Authorization",
  31. // "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImFkbWluIiwiZXhwIjoxNzY0NTMxMjM3fQ.15IfYua8M_cSE4i3kT86fanqO3OTG39fl2EJYXSQ1z8"
  32. // );
  33. // });
  34. // },
  35. },
  36. },
  37. },
  38. // 构建配置
  39. build: {
  40. outDir: "dist",
  41. sourcemap: false,
  42. // 消除打包大小超过500kb警告
  43. chunkSizeWarningLimit: 2000,
  44. rollupOptions: {
  45. output: {
  46. // 分包策略
  47. manualChunks: {
  48. "react-vendor": ["react", "react-dom"],
  49. "contentful-vendor": [
  50. "@contentful/f36-components",
  51. "@contentful/f36-icons",
  52. "@contentful/f36-tokens",
  53. ],
  54. },
  55. },
  56. },
  57. },
  58. };
  59. });