performance.transformLodash

  • Type: boolean
  • Default: true
  • Bundler: only support webpack

Specifies whether to modularize the import of lodash and remove unused lodash modules to reduce the code size of lodash.

This optimization is implemented using babel-plugin-lodash and swc-plugin-lodash under the hood.

Example

This option is enabled by default, and Modern.js will automatically redirects the code references of lodash to sub-paths.

For example:

input.js
import _ from 'lodash';
import { add } from 'lodash/fp';

const addOne = add(1);
_.map([1, 2, 3], addOne);

The transformed code will be:

output.js
import _add from 'lodash/fp/add';
import _map from 'lodash/map';

const addOne = _add(1);
_map([1, 2, 3], addOne);

Disabling the Transformation

In some cases, the import transformation of lodash may generate unexpected code. In such cases, you can manually disable this optimization:

export default {
  performance: {
    transformLodash: false,
  },
};