-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
lodash Dependency #1085
Comments
See the comments on #864, and #913. tl;dr this would make cheerio smaller on its own, but would prevent deduping in the common case of having other dependencies which depend on Lodash. Also, it would load far more code at runtime. Also, the upcoming version of Lodash will do away with the zero-dependency modules entirely. |
Thanks for your response. That's good to know! One thing I didn't fully understand was this "it would load far more code at runtime". Could you explain this a little further? |
Sure. Many Lodash functions depend on each other. The zero-dependency modules (one per function) are compiled to inline their dependencies into a single file. Therefore, modules for functions A and B which both depend on C each contain an identical copy of C. If you depend on In practice, the dependency chains are very long. For instance, the source for lodash.map is over 2000 lines long, as is the source for lodash.filter, with most code being duplicated between them. Depending on 12 of them would mean loading something like ~10x as much Lodash code at runtime. |
Awesome response @billyjanitsch |
I am interested in making cheerio as small as possible in terms of the footprint of its download size. There seems to be a pull request which specifies individual lodash module dependencies rather than all of lodash.
Using the lodash dependency declarations from this package, I was able to reduce the download size of cheerio significantly (by a few mbs, see the test project here).
Looking at the current version of package.json on the master branch, the lodash dependency declarations are reset to the complete lodash rather than the individual modules. Is there a reason why the individual module dependencies are not used?
(Please also see this related Stackoverflow question)
The text was updated successfully, but these errors were encountered: