Create smaller Lodash builds by replacing feature sets of modules with noop, identity, or simpler alternatives.
$ npm i --save-dev lodash-webpack-plugin babel-core babel-loader babel-plugin-lodash babel-preset-es2015 webpackvar LodashReplacementPlugin = require('lodash-webpack-plugin');
var webpack = require('webpack');
module.exports = {
'module': {
'loaders': [{
'loader': 'babel-loader',
'test': /\.js$/,
'exclude': /node_modules/,
'query': {
'plugins': ['lodash'],
'presets': ['es2015']
}
}],
'plugins': [
new LodashReplacementPlugin,
new webpack.optimize.OccurenceOrderPlugin,
new webpack.optimize.UglifyJsPlugin({
'compressor': {
'pure_getters': true,
'unsafe': true,
'warnings': false
}
})
]
}
};Opt-in to features by passing an options object:
new LodashReplacementPlugin({
'collections': true,
'paths': true
})The following features are removed by default (biggest savings first):
| Feature | Description |
|---|---|
shorthands |
Iteratee shorthands for _.property, _.matches, & _.matchesProperty. |
collections |
Support for objects in “Collection” methods like _.each, _.filter, & _.map. |
currying |
Support for _.curry & _.curryRight. |
caching |
Caches using Map & Set for methods like _.cloneDeep, _.isEqual, & _.uniq. |
coercions |
Coercion methods like _.toInteger, _.toNumber, & _.toString. |
paths |
Deep property path support for methods like _.get, _.has, & _.set. |
guards |
Dense array & iteratee call guards for methods like _.every, _.keys, & _.some. |
metadata |
Store metadata to reduce wrapping of bound, curried, & partially applied functions. (Requires currying) |
placeholders |
Argument placeholder support for methods like _.bind, _.curry, & _.partial.(Requires currying) |