-
Notifications
You must be signed in to change notification settings - Fork 2.8k
refactor: replace lodash with lodash-es for better tree-shaking #2882
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
base: master
Are you sure you want to change the base?
Conversation
|
|
commit: |
Co-authored-by: meet-student <[email protected]>
|
@copilot It seems that the effect is not significant, and you did not adjust the packaging related configurations |
... The ~0.6% reduction in UMD bundle is expected - the UMD bundle ( The key benefit is for consumers using ES module bundlers (webpack, rollup, Vite, etc.) who import from
With The packaging configs don't need changes - the tree-shaking benefit is realized on the consumer side, not in ahooks' own builds. |
[中文版模板 / Chinese template]
🤔 This is a ...
🔗 Related issue link
Addresses request to switch from
lodashtolodash-esfor better tree-shaking support.💡 Background and solution
lodashuses CommonJS exports which limits tree-shaking effectiveness.lodash-esprovides ES module exports enabling modern bundlers to eliminate unused code.Changes:
lodash→lodash-esin packages/hooks dependencies@types/lodash→@types/lodash-esin devDependencieslodash/*tolodash-es/*useThrottleFnanduseDebounceFnto fix TypeScript declaration portabilityBundle size (UMD):
Note on tree-shaking benefits:
The minimal UMD bundle reduction is expected - the UMD bundle (
dist/ahooks.js) includes all code and doesn't tree-shake since it's designed for direct browser usage.The primary benefit is for consumers using ES module bundlers (webpack, rollup, Vite, etc.) who import from
es/index.jsvia the"module"field. The package already has the required configurations:"module": "./es/index.js"- ES module entry point"sideEffects": false- Enables tree-shakingWith
lodash-es, when a consumer imports only specific hooks likeuseDebounceFn, their bundler can now tree-shake unused lodash functions. With the previouslodash(CommonJS), bundlers couldn't eliminate unused code even from the ES build. No packaging config changes are needed - the tree-shaking benefit is realized on the consumer side.📝 Changelog
☑️ Self Check before Merge
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.