Description
Replace date-fns with dayjs for date/time handling to reduce bundle size while maintaining functionality.
Comparison
| Feature |
date-fns |
dayjs |
| Bundle Size |
~75KB |
~2KB |
| Tree-shakeable |
Yes |
Plugin-based |
| Immutable |
Yes |
Yes |
| i18n support |
Yes |
Yes (plugins) |
| API style |
Functional |
Chainable |
Implementation
1. Install dayjs
bun add dayjs
bun remove date-fns
2. Migration example
// Before (date-fns)
import { format, parseISO } from 'date-fns';
const formatted = format(parseISO(date), 'PPP');
// After (dayjs)
import dayjs from 'dayjs';
const formatted = dayjs(date).format('MMMM D, YYYY');
3. Add locale support if needed
import dayjs from 'dayjs';
import 'dayjs/locale/ar';
dayjs.locale('ar'); // Set locale globally or per instance
Files to update
- All files importing from
date-fns
package.json
Description
Replace
date-fnswithdayjsfor date/time handling to reduce bundle size while maintaining functionality.Comparison
Implementation
1. Install dayjs
2. Migration example
3. Add locale support if needed
Files to update
date-fnspackage.json