The lodash
module is a combined module that consolidates and exports from various individual modules like lodash/pick
.
As a result:
import { pick } from 'lodash';
loads the entire lodash
module and then imports only one function from it.
import pick from 'lodash/pick';
directly loads just the lodash/pick
module and fetches its default export (pick
).
How do they impact the bundle size?
This largely depends on how well your bundler can perform tree-shaking. If you solely utilize the `pick` function from lodash and your bundler can optimize this, the impact should be similar. However, different bundlers vary in their efficiency of tree-shaking.
Do they import the exact same elements of lodash?
Both imports bring in the same content into your module, albeit through distinct methods (as mentioned above).
Are they relatively fast?
In terms of runtime speed, they should demonstrate comparable performance, posing no significant concerns.
When it comes to bundling time, the more complex processing your bundler must undertake, the longer it will take; this involves determining that although you're importing `lodash`, you exclusively use `pick`.
If you genuinely require only `pick`, the second approach ought to decrease the workload on the bundler.
To ascertain which option is more advantageous for your specific setup and codebase in aspects such as size, etc., experimentation may be necessary.