Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Lodash: tree shaking

When I try to use lodash function as a specific import as shown below then it shows to be it loads only 14.7KB in size. enter image description here

But when I try to use the import as a destructured object then it shows 69.6KB in size enter image description here

Some articles say it works the same for both the above imports while some say it doesn't. Just wanted to understand does it add the complete build or only a specific function in the final build, especially the 2nd syntax (destructuring)

like image 415
Varun Sukheja Avatar asked Dec 07 '25 02:12

Varun Sukheja


1 Answers

$ npm i -D babel-plugin-lodash

.babelrc
{
  ...,
  "plugins": [..., "lodash"]
}

This will allow for any import style (e.g. import _ from 'lodash', import { isEqual } from 'lodash' as the plugin will transform each usage of a lodash func to: import xyz from 'lodash/xyz';

like image 156
Dave K Avatar answered Dec 08 '25 16:12

Dave K