Creating Custom Lodash Builds
You can create custom builds of Lodash to include only the functions you need, reducing your bundle size.
Install the Lodash CLI:
npm i -g lodash-cli
Create a custom build:
lodash include=map,filter,reduce
With webpack or Rollup, you can use tree-shaking to automatically remove unused Lodash code:
import { map, filter } from 'lodash-es';
You can create a custom modularized build for more fine-grained control:
// myLodash.js
import map from 'lodash/map';
import filter from 'lodash/filter';
import reduce from 'lodash/reduce';
export { map, filter, reduce };
Then use it in your project:
import { map, filter } from './myLodash';
Custom builds can significantly reduce your bundle size when you’re only using a subset of Lodash functionality.
Last updated 1 day ago