![]() ![]() It goes without saying that handling the dates correctly is extremely important to any project, and replacing a dates library with another solution can seem to be a scary task. ![]() ![]() But jokes aside, you should check the types of browsers the users of your apps are using before making the decision to sail away from Moment. Legends say that there are still clients who expect to support dead browsers. Moment works well on IE 8 and higher, while alternative tools might not be compatible with older browsers-for example, Luxon supports IE 10 and higher. Seeing libraries already working on making themselves independent from Moment is reason for optimism, so calmly waiting for a release might be the best approach here. It might not be worth your time to jump into replacing all dependencies with a Moment-free alternative. Thankfully, many libraries and tools are working toward making themselves independent of Moment-Cypress removed Cypress.moment() in April ( release 7.0.0), and Ant Design provides a workaround for Moment (although Moment is still a dependency of antd). ![]() 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 |