Replace moment.js with date-fns #89
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Even though angular2-jsonapi only weighs about 3 KiB gzipped, it currently depends on moment.js, which adds about 65 KiB gzipped to a project. That absolutely kills the “lightweight” aspect of this library.
A major reason for moment.js being so big is that it bundles all its locales when imported, and getting rid of them requires fiddling with Webpack config (not currently possible with angular-cli). But even if all locales were removed, moment.js core is still 16 KiB gzipped, more than five times the size of this library’s core. We can do better!
This patch replaces moment with date-fns, a highly modular date library that allows us to import just the components we need, with minimal overhead. These are the numbers I got on my project:
(By the way, this patch preserves a serialization bug, as fixing it might break those who are already relying on it. I will make a different pull request for that)