Skip to content

Replace lodash with es-toolkit #239

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Replace lodash with es-toolkit #239

wants to merge 2 commits into from

Conversation

dayongkr
Copy link

@dayongkr dayongkr commented Jul 1, 2025

Replace lodash with es-toolkit for reduced bundle size

Summary

This PR replaces lodash.debounce dependency in babel-helper-define-polyfill-provider and lodash in build scripts with es-toolkit, achieving significant bundle size reduction while maintaining full compatibility.

Changes

  • babel-helper-define-polyfill-provider: Replaced lodash.debounce with es-toolkit/debounce
  • Build scripts: Replaced lodash with es-toolkit

Benefits

  • Bundle size reduction: debounce function code reduced from 378 lines to 110 lines (~3x smaller)
  • Cleaner implementation: es-toolkit removes unnecessary utilities like toNumber, isSymbol, etc., keeping only the essential logic needed for most use cases
  • Zero breaking changes: Build output diff shows identical results except for the migration itself
  • Full compatibility: es-toolkit/compat passes all lodash test cases and maintains 100% interface compatibility
  • Industry adoption: Already used by major projects like Storybook and Recharts

Performance Impact

While debounce functions don't typically have significant performance implications, the substantial bundle size reduction (3x smaller) provides clear value for end users.

Testing

  • ✅ All existing tests pass

  • ✅ Build output verification shows identical results

    • Screenshot 2025-07-02 at 12 07 55 AM
  • ✅ es-toolkit/compat compatibility confirmed through lodash test suite

Migration Details

The migration maintains the exact same API surface, ensuring this is a drop-in replacement with no changes required for consumers of this package.

@nicolo-ribaudo
Copy link
Member

Which Node.js versions does es-tooklit support?

@nicolo-ribaudo
Copy link
Member

Also sorry, but the es-toolkit npm package is 35x larger than the lodash.debounce (lodash is just a devDependency, so it doesn't really count):

package.json Outdated
@@ -93,5 +92,8 @@
}
},
"version": "0.0.0",
"packageManager": "[email protected]"
"packageManager": "[email protected]",
"dependencies": {
Copy link
Member

Choose a reason for hiding this comment

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

This should be a devDependency

Copy link
Author

Choose a reason for hiding this comment

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

Thanks for catching this!

@dayongkr
Copy link
Author

dayongkr commented Jul 1, 2025

Also sorry, but the es-toolkit npm package is 35x larger than the lodash.debounce (lodash is just a devDependency, so it doesn't really count):

While it's true that downloads would increase, since you can import only the functions(files) you need, the actual build output will be smaller than before.

@dayongkr
Copy link
Author

dayongkr commented Jul 1, 2025

For now, es-toolkit targets Node LTS versions, but I haven't measured the lodash compatibility layer like es-toolkit/compat.

I'll look this part, align it with simillar specs as lodash, and share the results through this PR again!

@nicolo-ribaudo
Copy link
Member

Note that these packages are used by Babel, which targets Node.js 6+. If it's not supported, we can revisit in a couple months after the Babel 8 stable release.

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

Successfully merging this pull request may close these issues.

2 participants