vite.config.ts 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import { defineConfig } from 'vite';
  2. import react from '@vitejs/plugin-react';
  3. // https://vite.dev/config/
  4. export default defineConfig({
  5. plugins: [react()],
  6. build: {
  7. // Enable minification for production builds (Req 13.9)
  8. // Vite 8+ uses oxc by default; 'esbuild' requires a separate install.
  9. // Leaving minify at its default ('oxc' in Vite 8) gives fast, aggressive
  10. // minification out of the box.
  11. // minify: 'esbuild', // uncomment if esbuild is installed separately
  12. // Raise the warning threshold slightly – Ant Design + Slate are large
  13. // but are split into their own vendor chunk below.
  14. chunkSizeWarningLimit: 600,
  15. rollupOptions: {
  16. output: {
  17. /**
  18. * Manual chunk splitting (Req 13.8)
  19. *
  20. * Splitting large vendor libraries into dedicated chunks means the
  21. * browser can cache them independently of app code. Tree-shaking
  22. * (built into Rollup by default) removes unused exports within each
  23. * chunk automatically (Req 13.9).
  24. *
  25. * Chunk strategy:
  26. * - react-vendor : React + React-DOM (stable, rarely changes)
  27. * - antd-vendor : Ant Design (large UI library, rarely changes)
  28. * - slate-vendor : Slate.js + slate-react + slate-history
  29. * - utils-vendor : Axios, Zustand, uuid (small but third-party)
  30. * - app code : everything under src/ (split by React.lazy)
  31. */
  32. manualChunks(id: string) {
  33. if (id.includes('node_modules/react') || id.includes('node_modules/react-dom')) {
  34. return 'react-vendor';
  35. }
  36. if (id.includes('node_modules/antd') || id.includes('node_modules/@ant-design')) {
  37. return 'antd-vendor';
  38. }
  39. if (
  40. id.includes('node_modules/slate') ||
  41. id.includes('node_modules/slate-react') ||
  42. id.includes('node_modules/slate-history')
  43. ) {
  44. return 'slate-vendor';
  45. }
  46. if (
  47. id.includes('node_modules/axios') ||
  48. id.includes('node_modules/zustand') ||
  49. id.includes('node_modules/uuid')
  50. ) {
  51. return 'utils-vendor';
  52. }
  53. // All other node_modules go into a generic vendor chunk
  54. if (id.includes('node_modules')) {
  55. return 'vendor';
  56. }
  57. },
  58. },
  59. // Rollup performs tree-shaking by default when building ES modules.
  60. // These options reinforce that unused exports are dropped (Req 13.9).
  61. treeshake: {
  62. moduleSideEffects: false,
  63. propertyReadSideEffects: false,
  64. },
  65. },
  66. },
  67. });