There are different solutions for this, although not all of them retain the capabilities of the chain.
Custom Lodash assembly (keeps the chain)
Use https://lodash.com/custom-builds with your custom methods. It will create the lodash assembly using the methods you need. The problem that I encountered in the past with this solution is that the assembly size size is quite high, although when importing several methods, as this requires the entire lodash function that wraps your data around it in order to be able to use the chain.
Import only the functions you need (no chain)
Most lodash features are available as standalone packages in npm ( example selection ), so you can import them separately. However, you will not have a chain with this solution.
Import functions from lodash src (no chain)
Another solution is to import certain functions from your full lodash module, so any connected one will use this function only with these dependencies, and not with the whole lodash, for example:
var pick = require('lodash/pick');
Tip. Do not use chaining
Despite the fact that you asked a question about a specific chain, I would like to dissuade you from using it, since this is a bad practice of functional programming. Check out this blog article (as you mentioned in your first comment) for a very detailed explanation of why itβs best not to use the chain and how to move away from it.
source share