![]() In order to determine how deeply your application depends on Moment, check your package-lock.json for any mentioning of Moment. As mentioned above, some of your libraries might also depend on Moment, which makes pruning it entirely out of your app a much harder task. Replacing Moment library entirely might take much more effort than swapping its applications in the code with a solution from another library or pure JavaScript. If you've come to the conclusion that you have some spare time on your hands and you want to start looking into replacing Moment as you'll have to do it at some point anyway, there are a few things to consider or do before you start making changes in the code. It might not be obvious that a library depends on Moment-for example, jsonwebtoken has it as a dependency-so check it before you kick off to save yourself time down the line. But one should avoid adding new dependencies that rely on Moment, as it would add to the code you will have to change in due time. More modern libraries take a different approach and secure immutability of objects.Īs mentioned at the beginning, Moment isn't a dead library and you can continue to use it in your project. ![]() It came as a surprise to many that one needs to use clone() on the Moment objects-it's an annoyance, and not the best practice. ![]() VFe8TFV9Y5- Addy Osmani 12, 2020Īnother reason why people were unhappy with Moment was the mutability of objects. Lighthouse in now recommends smaller libraries that improve bundle size. If JavaScript libraries are proving costly, replace them with smaller alternatives. In order to check the sizes yourself, clone the repos and run npm install, npm run build, npm run analyze.Īs you can see, the bundle with Moment is almost twice as big as the one with Luxon, while the bundle with day.js is only slightly bigger than the bundle without any of the libraries! For slower Internet connections and mobile users, the difference in bundle size might be noticeable.Įven Lighthouse in Chrome Dev Tools recommends replacing Moment with a smaller library. The table below compares the bundle sizes:
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |