vite.config.ts 1.6 KB

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