In comments on this performance audit of a React site, the lodash author suggests "cherry-picking" methods in lodash (i.e., require
ing individual methods instead of the whole lodash package) or using the individual packages. But shouldn't this be unnecessary if using a dead code eliminator such as uglify or the closure compiler as part of the bundling process (using browserify or webpack)?
If you are using CommonJS style require('lodash')
, Uglify doesn't dead code eliminate (I don't think Closure Compiler will be able to either).
However, if you are using ES6 style import { merge, reduce } from 'lodash'
(for example), you will be able to take advantage of tree-shaking using Webpack2 (some other bundlers support it, too). Since ES6 module system has a static structure, the bundler can perform static analysis and determine that certain parts of library are not used and eliminate them.
For more information about tree-shaking with Webpack 2, you can take a look at http://www.2ality.com/2015/12/webpack-tree-shaking.html.
As of writing this answer (March 3, 2016), Webpack 2 is still in beta, so there may be some issues but if you'd like to experiment, give it a try!