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

Added support for externals through peer dependencies #3674

Closed
wants to merge 1 commit into from
Closed

Added support for externals through peer dependencies #3674

wants to merge 1 commit into from

Conversation

subhero24
Copy link
Contributor

Allows parcel to not bundle the peerDependencies of a project and leave them as external requires. This makes it convenient to use parcel for bundling libraries or packages linked locally.

#144
#3305

It works by skipping the package in the node resolve algorithm if it was specified as a peer dependency (as if it was not there in the first place). The resolve algorithm can thus find the package higher up the tree where it was not specified as a peer dependency. In case it did not resolve (as all instances of the package in the tree are specified as a peer dependency), it will be ignored as a dependency and leave the require statement in place.

I find this useful for consuming local packages that have for example a "react" peer dependency. React should not be bundled multiple times as this makes React complain. Also useful to leave "@babel/runtime" requires in place for packages/libraries that want to depend on the babel runtime.

@DeMoorJasper
Copy link
Member

Looks like an interesting idea to use peerDeps for this.

Not entirely sure if this'll get merged as we have a feature lock on Parcel v1 to put all our focus on Parcel v2 and have the same amount or more features in Parcel 2 without Parcel 1 and 2 getting too much out of sync

@devongovett
Copy link
Member

Would you like to take a shot at implementing this in v2? The resolver is here: https://github.com/parcel-bundler/parcel/blob/v2/packages/resolvers/default/src/DefaultResolver.js#L143. You can return isExcluded: true to prevent a module from being bundled, so it should be even simpler than in v1. I don't think we need a CLI flag for this.

Going to close this PR. We aren't adding any new features to v1 at this point.

@subhero24
Copy link
Contributor Author

Ok, I will give this a go for v2

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.

None yet

3 participants