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

deps(lodash): migrate lodash to lodash-es to improve tree-shaking #16211

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ChristopherPHolder
Copy link
Contributor

@ChristopherPHolder ChristopherPHolder commented Oct 6, 2024

Summary

Improve Tree-Shaking and bundling by migrating from lodash to lodash-es.

Even tho we are now using individual imports as of #13914 we are still using ComonJS. But since the rest of the repo seems to have migrated to ESM we can now use the ESM packages for lodash which is lodash-es.

An addition benefit of this is that if the code is bundles futher by esbuild it will not require wrapping the use of lodash like this:

image

Related Issues/PRs

Copy link
Member

@adamraine adamraine left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just tested the bundle size, we go from 1807771 bytes to 1806087 bytes (so a savings of ~1.6KB)

@@ -12,7 +12,7 @@

/* eslint-disable no-console */

import cloneDeep from 'lodash/cloneDeep.js';
import cloneDeep from 'lodash-es/cloneDeep.js';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would expect the advantage of tree-shaking to be that we can import everything from the top-level entry point now. For example:

Suggested change
import cloneDeep from 'lodash-es/cloneDeep.js';
import {cloneDeep} from 'lodash-es';

Is this something you could do?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, will make the changes 👌

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

Successfully merging this pull request may close these issues.

4 participants