Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider importing only from the required files from lodash #703

Open
blutorange opened this issue Aug 2, 2024 · 1 comment
Open

Consider importing only from the required files from lodash #703

blutorange opened this issue Aug 2, 2024 · 1 comment

Comments

@blutorange
Copy link

blutorange commented Aug 2, 2024

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

@denisx
Copy link

denisx commented Oct 6, 2024

it is better to use "classic" lodash package, with atoms import. like "import debounce from 'lodash/debounce'"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants