Why Bundle Size Matters
Material UI’s maintainers take bundle size seriously. The team monitors size snapshots on every commit for every package using dangerJS, enabling detailed bundle size tracking on every pull request.Development vs Production
Modern bundlers tree-shake unused code in production builds automatically. However, during development, barrel imports can significantly slow down startup and rebuild times.Avoid Barrel Imports
Recommended Approach
Use direct path imports for optimal development performance:Avoid This Pattern
Icons Performance
The performance impact is especially noticeable with@mui/icons-material, which contains thousands of icons.
Fast Icon Imports
Slow Icon Imports
Migration: Codemod
If you have existing barrel imports, use the official codemod to convert them automatically:Enforce with ESLint
Prevent accidental barrel imports with ESLint’sno-restricted-imports rule:
@mui/material and @mui/icons-material while allowing @mui/material/Button.
VS Code Auto-Import Configuration
Prevent VS Code from auto-importing barrel files:Next.js Optimization
Next.js 13.5+ includes automatic import optimization viaoptimizePackageImports.
Automatic (Next.js 15.3+)
Material UI is optimized by default in Next.js 15.3 and later. No configuration needed.Manual Configuration (Next.js 13.5-15.2)
Add tonext.config.js:
Parcel Configuration
Parcel doesn’t resolvepackage.json "exports" by default, causing it to use CommonJS instead of ESM.
Enable the packageExports option:
Webpack Configuration
Webpack 5+ handles Material UI’s package exports correctly by default. No additional configuration is needed for tree-shaking.Production Build Analysis
Analyze your webpack bundle to verify tree-shaking:dist/report.html to see exactly which Material UI components are included.
Size Comparison
Here’s a real-world comparison from the Material UI repository:Minimal App (Button only)
- Gzipped: ~90 KB (includes React, ReactDOM, Emotion)
- Material UI portion: ~25 KB
Medium App (10 components)
- Gzipped: ~110 KB total
- Material UI portion: ~45 KB
- Incremental cost: ~20 KB for 9 additional components
Large App (50+ components)
- Gzipped: ~140 KB total
- Material UI portion: ~75 KB
- Diminishing incremental cost due to shared dependencies
Tree-Shaking Requirements
For optimal tree-shaking:- Use ESM builds - Material UI publishes both CommonJS and ES modules
- Configure
sideEffects- Already configured in Material UI’spackage.json - Production mode - Ensure
NODE_ENV=production - Minification - Use Terser or equivalent
"sideEffects": false declaration tells bundlers that no files have side effects, enabling aggressive tree-shaking.
Development Server Performance
Measured impact on development server startup with a typical Material UI app:| Import Style | Initial Startup | Hot Reload |
|---|---|---|
Barrel imports (@mui/material) | 3.2s | 450ms |
Direct imports (@mui/material/Button) | 1.8s | 180ms |
Common Patterns
Single Component Import
Multiple Components
With TypeScript Types
Theme and Utilities
Production Checklist
Before deploying:- Verify
NODE_ENV=production - Check bundler uses ESM imports
- Confirm minification is enabled
- Run bundle analyzer to verify no duplicate packages
- Test production build size vs development
- Monitor lighthouse performance score