// 性能优化配置文件 module.exports = { // 资源预加载策略 preload: { // 关键资源预加载 critical: ['vue-vendor', 'element-ui', 'main'], // 预获取异步资源 prefetch: true, // 字体预加载 fonts: [ '/font/iconfont.woff2', '/font/youaimoshouruifang.ttf' ] }, // 图片优化 images: { // 内联阈值 inlineLimit: 4 * 1024, // 4KB // 压缩配置 compression: { jpeg: { quality: 85, progressive: true }, png: { quality: [0.65, 0.90], speed: 4 }, webp: { quality: 85 }, svg: { plugins: [{ name: 'preset-default' }] } }, // 支持的格式 formats: ['webp', 'avif', 'jpg', 'png'], // 响应式图片 responsive: { sizes: [320, 640, 960, 1280, 1920], formats: ['webp', 'jpg'] } }, // 代码分割策略 splitChunks: { strategy: 'balanced', // 平衡策略 maxInitialRequests: 6, maxAsyncRequests: 8, minSize: 100000, // 100KB maxSize: 8000000, // 8MB // 分包规则 groups: { vue: { priority: 30, test: /vue|vue-router|vuex/ }, elementUI: { priority: 25, test: /element-ui/ }, largeLibs: { priority: 23, test: /echarts|artplayer|hls\.js/ }, utils: { priority: 21, test: /lodash|moment|axios/ }, ctComponents: { priority: 20, test: /@ct/ }, vendor: { priority: 10, test: /node_modules/ } } }, // 缓存策略 cache: { type: 'filesystem', maxAge: 7 * 24 * 60 * 60 * 1000, // 7天 compression: 'gzip', buildDependencies: ['config'] }, // 压缩配置 compression: { gzip: { threshold: 8192, // 8KB minRatio: 0.8, algorithm: 'gzip' }, brotli: { threshold: 8192, minRatio: 0.8, level: 11 } }, // 开发服务器优化 devServer: { writeToDisk: false, compress: true, hot: true, stats: 'errors-warnings' }, // 构建优化 build: { // 并行处理 parallel: 2, // 生产环境优化 production: { dropConsole: true, dropDebugger: true, minify: true, extractCSS: true }, // 开发环境优化 development: { sourcemap: 'eval-cheap-module-source-map', cache: true, hmr: true } }, // 监控和分析 analyze: { // 包大小分析 bundleAnalyzer: false, // 性能预算 performanceBudget: { maxAssetSize: 2000000, // 2MB maxEntrypointSize: 2000000, // 2MB hints: 'warning' } } }