back
2 comments
A lot of Lodash functions are implemented as combinations of other Lodash functions, so importing a single function actually imports half of Lodash under the hood:

https://github.com/lodash/lodash/blob/main/src/.internal/bas...

Would it be shorter if it didn’t, though?
Glimpsing at the source code - yes, definitely.

For example, the code imports "copyArray", a 9LoC function that does exactly the same as the built-in Array.slice() would do.

Same goes for other imported helpers like "arrayEach", which could be replaced by the built-in Array.every().

It's basically a bunch of unnecessary polyfills for built-ins.

Unnecessary _now_ perhaps, but not unnecessary when lodash was written. In 2009, when underscore.js came out (from which lodash was a fork) Array.every() was not something you could rely on. Chrome just came out a year earlier (and didn't support Array.every until version 4) and half the world was on IE 6-7-8
The expectation is that you import the whole library and not just one function. At which point, lodash is smaller than if each function was implemented separately.
I actively fight for removal of lodash in every frontend codebase I encounter. The cost is just too much. Often I run into developers who tell me there's some sort of webpack plugin to treeshake all the `import _ from 'lodash';` nonsense. The truth is, when we run a bundle analyzer, it's still one of the biggest bloaters. Webpack is also becoming less common in newer codebases. The point is, while it provides a ton of convenience methods, there is a cost.