dspace-angular
dspace-angular copied to clipboard
Replace Moment.js with date-fns
Description
In an attempt to start to shrink the size of our main.js, this PR replaces moment.js with date-fns (which is much smaller in size)
- Why? Because Moment.js doesn't work with "tree-shaking" and it can expand the size of your bundle. See https://github.com/you-dont-need/You-Dont-Need-Momentjs/blob/master/README.md
This PR decreases the GZipped size of main.js
by ~66KB. This measurement was determined by running the following on main
vs this PR:
-
yarn build:stats
-
webpack-bundle-analyzer .\dist\browser\stats.json
Instructions for Reviewers
- Review code
- Run some basic tests with date-based functionality to ensure no changes in behavior.
- For example: Saving date in submission, filtering by date in search results, etc.
List of changes in this PR:
- Created new specs for
date.util.ts
to verify the current behavior using momentjs is validated. These tests pass with momentjs. - Refactored code in
date.util.ts
to usedate-fns
instead, verifying the same tests still pass - Refactored
search-range-filter.component.ts
to parse the necessary year via a newyearFromString()
method indate.util.ts
and added tests to verify it behaves the same as the old momentjs code. - Removed
ngx-moment
which didn't appear to be used anywhere in our codebase.
Include guidance for how to test or review your PR. This may include: steps to reproduce a bug, screenshots or description of a new feature, or reasons behind specific changes.
This pull request introduces 1 alert when merging 502d4bbdb11fe0c132f0f5c3aea98d93d05d0df4 into 273c7543707ccdad44c7fcafcfa967c1fd0b98e9 - view on LGTM.com
new alerts:
- 1 for Unused variable, import, function or class
This PR is highly appreciated. Thank you @tdonohue.
@artlowel : Assigning to you for review as you volunteered to look at shrinking main.js. Please feel free to delegate if you wish.
Merging, as this is at +1. Minor feedback was addressed and tests still pass.