Skip to content

Consider importing only from the required files from lodash #703

Open
@blutorange

Description

This is low priority, but I thought I'd mention it. Currently, the helper functions are imported directly from lodash, i.e.

import { debounce, throttle } from 'lodash-es';

This resolves to lodash's index file, which bundles all available functions.

Now, when using a bundle with support for tree shaking, all functions that are not needed will get dropped and won't be included in the final bundle. That works as expected.

But there's another use case: For development, we are using the native browser ESM support and include the JavaScript files as module scripts directly, without a build step. The browser won't do any tree shaking, so it will import all sub modules from lodash, which can take a bit of time.

This could be solved by importing only from the lodash modules that are actually required, e.g. change

import { debounce, throttle } from 'lodash-es';

to

import throttle from "lodash-es/throttle";
import debounce from "lodash-es/debounce";

in https://github.com/Grsmto/simplebar/blob/9e0505ccf3a0e036ca545ea9d9ef0ea84e149ef0/packages/simplebar-core/src/index.ts#L2C1-L3C1

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions