ClaudeForge bundle size analysis and optimization specialist for webpack, rollup, and modern build tools.
/plugin marketplace add claudeforge/marketplace/plugin install bundle-analyzer@claudeforge-marketplaceClaudeForge intelligent bundle analysis system that identifies, analyzes, and optimizes JavaScript bundle sizes with comprehensive visualization, tree shaking recommendations, and automated code splitting strategies.
Transform bundle optimization from manual investigation to intelligent automation that ensures optimal application performance, minimal load times, and efficient code delivery across modern web applications.
/bundle-analyzer [command] [options]
Target: $ARGUMENTS (if specified, otherwise analyze current build output)
Full Bundle Analysis:
/bundle-analyzer analyze --build-dir=dist --format=html
Generates comprehensive bundle analysis including:
Webpack Bundle Analysis:
/bundle-analyzer webpack --stats-file=stats.json --threshold=500kb
Analyzes webpack bundles with:
Source Map Explorer:
/bundle-analyzer source-map --bundle=main.js --output=report.html
Uses source-map-explorer for:
Tree Shaking Optimization:
/bundle-analyzer tree-shake --aggressive --side-effects-check
Optimizes tree shaking with:
Code Splitting Strategy:
/bundle-analyzer code-split --strategy=route-based --max-chunk=250kb
Implements intelligent code splitting:
Dependency Optimization:
/bundle-analyzer dependencies --find-duplicates --suggest-alternatives
Optimizes dependency usage:
Performance Budget:
/bundle-analyzer budget --max-initial=500kb --max-route=250kb --fail-on-breach
Enforces performance budgets with:
Compression Analysis:
/bundle-analyzer compress --algorithms=gzip,brotli,zstd --level=11
Analyzes compression effectiveness:
Import Cost Analysis:
/bundle-analyzer imports --annotate --threshold=50kb
Provides import-level insights:
Core Web Vitals Impact:
Size Categories:
Tree Shaking Excellence:
// Bad: CommonJS imports prevent tree shaking
const _ = require('lodash');
const cloneDeep = _.cloneDeep;
// Good: ESM named imports enable tree shaking
import { cloneDeep } from 'lodash-es';
// Best: Direct function imports minimize bundle size
import cloneDeep from 'lodash-es/cloneDeep';
Code Splitting Patterns:
// Route-based splitting
const Dashboard = lazy(() => import('./pages/Dashboard'));
const Profile = lazy(() => import('./pages/Profile'));
// Component-based splitting with prefetch
const HeavyChart = lazy(() => import(
/* webpackChunkName: "chart" */
/* webpackPrefetch: true */
'./components/HeavyChart'
));
// Dynamic import with error boundary
const loadModule = () => import('./module').catch(err => {
console.error('Module load failed:', err);
return { default: FallbackComponent };
});
Webpack Configuration Optimization:
// Optimal SplitChunks configuration
optimization: {
splitChunks: {
chunks: 'all',
cacheGroups: {
vendor: {
test: /[\\/]node_modules[\\/]/,
name(module) {
const packageName = module.context.match(
/[\\/]node_modules[\\/](.*?)([\\/]|$)/
)[1];
return `vendor.${packageName.replace('@', '')}`;
},
priority: 10
},
common: {
minChunks: 2,
priority: 5,
reuseExistingChunk: true,
enforce: true
}
}
},
runtimeChunk: 'single',
moduleIds: 'deterministic'
}
Installation and Setup:
npm install --save-dev webpack-bundle-analyzer
Configuration:
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
module.exports = {
plugins: [
new BundleAnalyzerPlugin({
analyzerMode: 'static',
reportFilename: 'bundle-report.html',
openAnalyzer: false,
generateStatsFile: true,
statsFilename: 'bundle-stats.json'
})
]
};
Analysis Workflow:
# Generate source maps
npm run build -- --source-map
# Analyze main bundle
npx source-map-explorer dist/main.*.js --html dist/sme-report.html
# Compare bundles
npx source-map-explorer dist/*.js --only-mapped
Dependency Size Checking:
# Check package size before installation
npx bundle-phobia moment
# Compare alternatives
npx bundle-phobia moment date-fns dayjs
# Size impact analysis
npx bundle-phobia --interactive
Library Alternatives:
Tree Shaking Optimization:
{
"sideEffects": [
"*.css",
"*.scss",
"./src/polyfills.js"
]
}
Vite Optimization:
// vite.config.js
export default {
build: {
rollupOptions: {
output: {
manualChunks: {
'react-vendor': ['react', 'react-dom'],
'ui-vendor': ['@mui/material', '@mui/icons-material'],
'utils': ['lodash-es', 'date-fns']
}
}
},
chunkSizeWarningLimit: 500,
minify: 'terser',
terserOptions: {
compress: {
drop_console: true,
drop_debugger: true
}
}
}
};
Rollup Optimization:
// rollup.config.js
export default {
plugins: [
terser({
compress: {
passes: 2,
pure_getters: true,
unsafe: true
},
mangle: {
safari10: true
}
}),
visualizer({
filename: 'bundle-analysis.html',
gzipSize: true,
brotliSize: true
})
]
};
name: Bundle Size Check
on: [pull_request]
jobs:
bundle-size:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
- name: Install dependencies
run: npm ci
- name: Build and analyze
run: npm run build
- name: Analyze bundle size
uses: andresz1/size-limit-action@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
limit: "500 KB"
- name: Comment PR with bundle report
uses: marocchino/sticky-pull-request-comment@v2
with:
path: bundle-report.md
{
"size-limit": [
{
"name": "Initial Bundle",
"path": "dist/main.*.js",
"limit": "500 KB",
"gzip": true
},
{
"name": "Total App Size",
"path": "dist/**/*.js",
"limit": "1.5 MB",
"gzip": true
}
]
}
Comprehensive Analysis Report:
Summary Statistics:
Bundle Analysis Summary
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Total Bundle Size: 1.2 MB (489 KB gzipped)
Initial Load: 456 KB (189 KB gzipped)
Lazy Chunks: 744 KB (300 KB gzipped)
Top 5 Largest Modules:
1. node_modules/react-dom/cjs/react-dom.production.min.js - 120 KB
2. node_modules/@mui/material/esm/index.js - 87 KB
3. node_modules/recharts/es6/index.js - 65 KB
4. src/pages/Dashboard/index.js - 43 KB
5. node_modules/date-fns/esm/index.js - 38 KB
Optimization Opportunities:
• Replace moment.js with date-fns (saves 54 KB)
• Enable aggressive tree shaking (potential 120 KB reduction)
• Split vendor bundle into smaller chunks
• Consider dynamic imports for Dashboard (43 KB)
Performance Budget Status: ⚠️ WARNING
Initial bundle exceeds recommended 400 KB limit
Programmatic Analysis:
{
"bundles": [
{
"name": "main",
"size": 456000,
"gzipSize": 189000,
"modules": 342,
"duplicates": 3
}
],
"recommendations": [
{
"type": "dependency-replacement",
"module": "moment",
"suggestion": "date-fns",
"savings": 54000
}
]
}
ClaudeForge Bundle Analyzer - Intelligent bundle size optimization with comprehensive analysis, actionable recommendations, and automated performance monitoring.