Replacing moment.js with date-fns having chart.js installed

916 views Asked by At

I have an angular app using moment.js and chart.js modules.

After replacing moment.js with date-fns I noticed that the size of the vendor.js file increased while it should've been decreased. After visualizing the content of it and searching for any dependencies on moment.js I saw a few things:

  1. moment.js wasn't deleted from node_modules but only from package.json after using npm prun and npm uninstall moment --save and more..
  2. The vendor.js file contains both the date-fns and moment.js modules.
  3. package-lock.json list moment.js as a dependency of my project and it's a dependency of chart.js too.

First of all, I'd like to confirm that the reason the moment.js appears in all of the above is that it's chart.js's dependency.

Secondly, how can I truly remove moment.js and get the vendor.js to be lighter?

Thanks a lot!

1

There are 1 answers

2
lewisbm On

Indeed, moment.js is a chart.js's dependency. Here are a few options to avoid importing moment

Your size bundle increased because now you have moment and date-fns