refactor: replace lodash with lodash-es for better tree-shaking - #2882
refactor: replace lodash with lodash-es for better tree-shaking#2882meet-student with Copilot wants to merge 2 commits into
Conversation
|
|
commit: |
Co-authored-by: meet-student <59312002+meet-student@users.noreply.github.com>
|
@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.