0 Tk

Custom Builds

Creating Custom Lodash Builds

You can create custom builds of Lodash to include only the functions you need, reducing your bundle size.

Using the Lodash CLI

  1. Install the Lodash CLI:

    npm i -g lodash-cli
    
  2. Create a custom build:

    lodash include=map,filter,reduce
    

Using Module Bundlers

With webpack or Rollup, you can use tree-shaking to automatically remove unused Lodash code:

import { map, filter } from 'lodash-es';

Creating a Custom Modularized Build

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.

Previous: Lodash FP

Last updated 1 day ago