New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
NPM package size of moment.js is bothersome #3376
Comments
People use moment in different ways, and the general consensus is that disk space in a node app is not a premium in the same way that it is in the browser. That said, I'm not sure exactly what's going on in the I'm not sure why we need Also, there shouldn't be a need for non-minimized files in a |
The min folder is really just misnamed. Built might be a better name. But that's just where the moment-with-locales and locales files live until we run the update-index grunt task for release. We could certainly take the moment-with-locales files out of npm specifically, but I'm not sure what value it provides. |
@martinheidegger can you please explain under what conditions is the size of the whole package a problem. The package grows as people want more options to consume the library. If we are to remove the things you list we need to publish separate packages that are minimal in some respect, and then publish also a large package that has everything. Can you give an example with another library that cuts everything to bare minimum in some/all of its npm builds? |
npm install of lodash is 1.4 MB while minified it's only 69 KB And there are a lot more, event a lot bigger, here are just some of them
|
While I don't really care of the size of the npm package, I do find astonishing that I have to include 58KB for manipulated dates in a sane way (assuming I don't need locales, which are way heavier) 😞 |
I am tired of arguing this sort of thing. I thought lower footprint would make the installation of my package faster (of which moment is the biggest one). I guess I am running against windmills. So: kthxbye. |
@martinheidegger give yarn a try, at least they are more sane than npm and cache the package, so you shouldn't spend as much time on downloads :) |
I'm facing the same issue. Doing |
@paramsingh88 Sounds like the only option is to not use it. Found this thread because of the same issue. My project size increases by 58kB by simply doing |
I don't understand this attitude:
The problem is that moment is not a node app - it's a library that can be used either in a backend application or in the front-end library. In this case, yes, I do need to use Moment.js to validate dates on the front-end of the application before sending them to the backend (which has it's own, seperate, validation.) |
The size of moment without locales is 50k (minified), the size with locales is around 300k (minified). If you want to do something about it check the discussion in here #2373
Sorry, my bad. (edited) |
I don't think you can build a good lib with this kind of mindset. The moment people realize bundle size is a real issue, and you chose to do nothing about it, |
Hi, npm moment is about 3mb, however this impacts the size of lambda edit inline tool. shrinking would definitely help |
Using this in an Angular app gzipped ends up being 70% the size of my smaller bundles. Would be awesome if we could exclude features we don't need as at the moment I have to |
@silentsnooc On runtime, you're supposed to load only locales you need. So the main concern for you is to lazy-load locales files only when you use them. |
@kylekatarnls If you could show an example for those of us using bundlers, that would be helpful. Thanks. |
The example for JSPM given in the doc here: also work for webpack, and I guess it can do the job for other bundlers. |
Not tried, but this comment has a lot of likes: |
I believe moments.js was not meant to be used in the browser front end and there were no plans from maintainers to do so. When we got hit with the similar problem we ended up using |
find a more small size lib, which is an alternative to
|
Just replaced momentjs with dayjs. Seems to be working well for my purposes and it's only around 15Kb with locale and fromNow plugin set. Fantastic. |
Ionic 4/ Angular 8 app bundle size differences: with with I just need basic data/time formatting and manipulations only. So I have decided to go with |
This worked well for everyone searching for a quick optimization. |
I checked the file-size of my
./node_modules
folder and it seems that moment.js is the heaviest non-C library. 2.1MB is quite a lot. A quick look in the folder size shows:Most of the weight comes from publishing compressed versions of moment.js with
npm
as well as double-publish all the locales. But the locales alone are quite heavy by themselves.As such I thought it might be good for moment.js and the community to reduce this amount?!
./src
folder from being published tonpm
?./min
folder from being published tonpm
?./locales
folder into a separatenpm
package to reduce moment to the minimum?The text was updated successfully, but these errors were encountered: