Images in this project are automatically optimized using npm scripts with imagemin. This ensures fast loading times in production without requiring global tools.
# Install dependencies
npm install
# Optimize images (creates optimized versions without modifying originals)
npm run optimize-images
# Review optimized images in: src/assets/images-optimized/
# Apply optimized images (backs up originals first)
npm run optimize-images:apply| Script | Description |
|---|---|
npm run optimize-images |
Optimizes all images in src/assets/images/ and saves to src/assets/images-optimized/ |
npm run optimize-images:apply |
Backs up originals and applies optimized images |
npm run build |
Automatically runs image optimization before building |
The optimization script (scripts/optimize-images.js) uses:
- sharp: Converts all image formats (HEIC, PNG, etc.) to JPG format
- imagemin-mozjpeg: Compresses JPG images (quality: 85%, progressive)
Behavior:
- All images are converted to JPG format (HEIC, PNG, etc. → JPG)
- Images ≥ 5MB: Converted to JPG AND optimized/compressed
- Images < 5MB: Converted to JPG only (no compression/optimization applied)
src/assets/
├── images/ # Original images (source)
├── images-optimized/ # Optimized versions (created by script, gitignored)
└── images-backup/ # Backup of originals (created when applying, gitignored)
Optimization settings can be adjusted in scripts/optimize-images.js:
const config = {
jpeg: {
quality: 85,
progressive: true,
},
};- Development: Work with original images in
src/assets/images/ - Before Build: Run
npm run optimize-imagesto create optimized versions - Review: Check
src/assets/images-optimized/to ensure quality is acceptable - Apply: Run
npm run optimize-images:applyto replace originals - Build: Run
npm run build(optimization runs automatically)
- Original total size: ~150MB+
- Optimized total size: < 5MB
- Size reduction: 95%+
- Load time improvement: 70-90%
- Lazy Loading: Images use
loading="lazy"for non-critical images - Priority Loading: Critical images use
fetchpriority="high" - Async Decoding: All images use
decoding="async" - Build Optimizations: Vite config optimized for better asset handling
# Make sure dependencies are installed
npm install# If you have a backup
mv src/assets/images-backup src/assets/imagesEdit scripts/optimize-images.js and adjust the config object.
- Original images are never modified until you run
optimize-images:apply - All images (HEIC, PNG, etc.) are converted to JPG format only
- HEIC files (like
mb_2.heic) are automatically converted to JPG during optimization - The build process automatically optimizes images, so you don't need to run it manually before deployment