Tree Shaking Lodash with Webpack 3.8.1

168 Views Asked by At
  • [email protected]

  • [email protected]

  • babel@7

  • [email protected]

    I use named imports when it comes to Lodash. I've configured @babel/preset-env with 'modules' set to false to prevent transpilation to Common JS and use 'lodash' as a plugin in the 'babel-loader' config. Despite all this, I realised my chunk has the entire Lodash, and is significantly bloating it up. What can I do to enable lodash from getting pruned? I am neither importing the entire library in my code , nor am I using chaining.

1

There are 1 best solutions below

2
Eric Simonton On

I maintain a library of (much) smaller versions of lodash functions. It is written using a modern build chain, so tree shaking should happen easily. You could check whether it has everything you need: micro-dash.