performance.config.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. // 性能优化配置文件
  2. module.exports = {
  3. // 资源预加载策略
  4. preload: {
  5. // 关键资源预加载
  6. critical: ['vue-vendor', 'element-ui', 'main'],
  7. // 预获取异步资源
  8. prefetch: true,
  9. // 字体预加载
  10. fonts: [
  11. '/font/iconfont.woff2',
  12. '/font/youaimoshouruifang.ttf'
  13. ]
  14. },
  15. // 图片优化
  16. images: {
  17. // 内联阈值
  18. inlineLimit: 4 * 1024, // 4KB
  19. // 压缩配置
  20. compression: {
  21. jpeg: { quality: 85, progressive: true },
  22. png: { quality: [0.65, 0.90], speed: 4 },
  23. webp: { quality: 85 },
  24. svg: { plugins: [{ name: 'preset-default' }] }
  25. },
  26. // 支持的格式
  27. formats: ['webp', 'avif', 'jpg', 'png'],
  28. // 响应式图片
  29. responsive: {
  30. sizes: [320, 640, 960, 1280, 1920],
  31. formats: ['webp', 'jpg']
  32. }
  33. },
  34. // 代码分割策略
  35. splitChunks: {
  36. strategy: 'balanced', // 平衡策略
  37. maxInitialRequests: 6,
  38. maxAsyncRequests: 8,
  39. minSize: 100000, // 100KB
  40. maxSize: 8000000, // 8MB
  41. // 分包规则
  42. groups: {
  43. vue: { priority: 30, test: /vue|vue-router|vuex/ },
  44. elementUI: { priority: 25, test: /element-ui/ },
  45. largeLibs: { priority: 23, test: /echarts|artplayer|hls\.js/ },
  46. utils: { priority: 21, test: /lodash|moment|axios/ },
  47. ctComponents: { priority: 20, test: /@ct/ },
  48. vendor: { priority: 10, test: /node_modules/ }
  49. }
  50. },
  51. // 缓存策略
  52. cache: {
  53. type: 'filesystem',
  54. maxAge: 7 * 24 * 60 * 60 * 1000, // 7天
  55. compression: 'gzip',
  56. buildDependencies: ['config']
  57. },
  58. // 压缩配置
  59. compression: {
  60. gzip: {
  61. threshold: 8192, // 8KB
  62. minRatio: 0.8,
  63. algorithm: 'gzip'
  64. },
  65. brotli: {
  66. threshold: 8192,
  67. minRatio: 0.8,
  68. level: 11
  69. }
  70. },
  71. // 开发服务器优化
  72. devServer: {
  73. writeToDisk: false,
  74. compress: true,
  75. hot: true,
  76. stats: 'errors-warnings'
  77. },
  78. // 构建优化
  79. build: {
  80. // 并行处理
  81. parallel: 2,
  82. // 生产环境优化
  83. production: {
  84. dropConsole: true,
  85. dropDebugger: true,
  86. minify: true,
  87. extractCSS: true
  88. },
  89. // 开发环境优化
  90. development: {
  91. sourcemap: 'eval-cheap-module-source-map',
  92. cache: true,
  93. hmr: true
  94. }
  95. },
  96. // 监控和分析
  97. analyze: {
  98. // 包大小分析
  99. bundleAnalyzer: false,
  100. // 性能预算
  101. performanceBudget: {
  102. maxAssetSize: 2000000, // 2MB
  103. maxEntrypointSize: 2000000, // 2MB
  104. hints: 'warning'
  105. }
  106. }
  107. }