docs(guides): fix lodash classification from peerDependency to depend…#8094
Open
jay7-tech wants to merge 1 commit intowebpack:mainfrom
Open
docs(guides): fix lodash classification from peerDependency to depend…#8094jay7-tech wants to merge 1 commit intowebpack:mainfrom
jay7-tech wants to merge 1 commit intowebpack:mainfrom
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
| ## Externalize Lodash | ||
|
|
||
| Now, if you run `npx webpack`, you will find that a largish bundle is created. If you inspect the file, you'll see that lodash has been bundled along with your code. In this case, we'd prefer to treat `lodash` as a _peer dependency_. Meaning that the consumer should already have `lodash` installed. Hence you would want to give up control of this external library to the consumer of your library. | ||
| Now, if you run `npx webpack`, you will find that a largish bundle is created. If you inspect the file, you'll see that lodash has been bundled along with your code. In this case, we'd prefer to treat `lodash` as a dependency. By declaring it as a `dependency` in your `package.json` and externalizing it in your webpack config, you give up control of this external library to the consumer's package manager, preventing duplicate bundles. |
Member
There was a problem hiding this comment.
It can be dependency, dev dependency and peer dependency depending on how you bundling your library
Author
There was a problem hiding this comment.
Yeaahh,
The ideal dependency classification strictly relies on the consumers bundling architecture.
I've updated the guide to explicitly map out dependencies (npm resolution), devDependencies (pre-bundled dists), and peerDependencies (externalized singletons like React/Lodash) so the scenarios are unambiguous. I Just pushed the patch
cf9152d to
9fc7f47
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #6896.
(Incorrect advice to use peerDependencies for utility libraries).
The Authoring Libraries guide was advising developers to treat utility libraries like lodash as peerDependencies to avoid bundle bloat when externalizing them. However, a in the issue, if a library relies on lodash internally at runtime, it must be listed in dependencies.
peerDependencies are strictly for packages that a consumer must install directly in their own app to satisfy the library's environment (eg React for a UI component library). dependencies guarantees the package manager installs the utility library automatically.
This PR simply correctly updates the text to advise using dependencies instead, while keeping the explanation of how to externalize it in the webpack config to prevent duplication.
What kind of change does this PR introduce?
Fix / Documentation
Did you add tests for your changes?
NA
Does this PR introduce a breaking change?
No.
If relevant, what needs to be documented once your changes are merged or what have you already documented?
N/A
Use of AI
None.