Ship modules without moment.js

Moment.js is a great and comprehensive library to use date, times, and formatting.

Why should we use it ? Because the Date interface in javascript is lacking of flexibility. It also permits to to translate a moment in a any locale and language.

Why should not we use it ? 232 kB (or 66 kB gzipped). 68kB without the translations.

So what would you do if you need to demo or bundle a component depending on moment.js, but without the library ?

You can either use Date but it is kind of difficult. Or use a lighter library. Or fake out moment.js like I do.

I wrote a dedicated fake version of moment.js to reproduce the behavior of the library without having to to pull it.

The attempt can be read and reused from this URL :

This version only weights 4.6kB. It only has a few of the existing operations but they do work.
And of course, you can make your bundler use this module when importing ‘moment’ by using import aliases.

Don’t hesitate to copy or fork for your own needs.

Leave a Reply

Your email address will not be published. Required fields are marked *


This site uses Akismet to reduce spam. Learn how your comment data is processed.