name: 包大小分析器 description: 分析和优化桌面应用程序的包大小 allowed-tools: Read, Write, Edit, Bash, Glob, Grep tags: [性能, 包大小, 优化, webpack, 桌面应用]
包大小分析器
分析和优化应用程序包大小,以改善下载时间和内存使用。
功能
- 分析包组成
- 识别大型依赖项
- 检测重复包
- 建议树摇优化机会
- 生成大小报告
- 跟踪大小随时间变化
输入模式
{
"type": "object",
"properties": {
"projectPath": { "type": "string" },
"bundler": { "enum": ["webpack", "vite", "rollup", "esbuild"] },
"generateReport": { "type": "boolean", "default": true }
},
"required": ["projectPath"]
}
Webpack 包分析器
// webpack.config.js
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
module.exports = {
plugins: [
new BundleAnalyzerPlugin({
analyzerMode: 'static',
reportFilename: 'bundle-report.html'
})
]
};
优化技术
- 树摇
- 代码分割
- 动态导入
- 替换重型依赖项
- 压缩资源
大小目标
| 应用类型 | 目标 | 可接受 | 过大 |
|---|---|---|---|
| 简单工具 | < 30MB | < 60MB | > 100MB |
| 标准应用 | < 80MB | < 150MB | > 250MB |
| 复杂应用 | < 150MB | < 250MB | > 400MB |
相关技能
启动时间分析器electron-builder配置