-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
A draft conditional bundling approach #9661
base: v2
Are you sure you want to change the base?
Conversation
Do we need a new dependency priority here? It seems very similar to the const { Component } = globalThis.__conditions['my.feature.flag'] ? require('./NewComponent') : require('./OldComponent'); where those require dependencies had |
@devongovett I did have a look at the existing priorities but there was some reason that I thought parallel might not be suitable that I can't remember now. If the conditional bundles were |
↪️ Pull Request
This is a partially working draft implementation of an approach for a specific type of conditional bundling that is designed for feature flags more than any other more general purpose "conditions".
The intention is that the end-user will not pay the download cost for code they will not execute because they do not have the feature flag enabled.
What it does
As a developer, you write:
At runtime this will give you either the
Component
export fromNewComponent
orOldComponent
. It is important to note that this is a synchronous import, it does not require a "tick" to return the module.How it works
Currently we're essentially using the same underlying mechanisms as for dynamic imports to have Parcel produce new bundle groups for each of the "true" and "false" arms of the condition.
The
importCond
is replaced with aparcelRequire
to a runtime asset that looks like:It is up to the server to have:
my.feature.flag
feature flag and rendered the<script />
tag(s) for the correct bundle group (I mean, realistically it could render both bundle groups but that would negate the whole point of avoiding shipping the code)<script />
that setswindow.__conditions = { 'my.feature.flag' : (true|false) }
for the runtime to use.There is a Reporter that is currently in my test repo, that calls
unstable_getConditionalBundleMapping
in order to get the information needed for a server manifest.What's missing from the draft implementation
ScopeHoistingPackager
to ensure the dependency rewrites work correctlyWhat I'm looking for
As this is all behind a feature flag, I'd still be keen on getting it merged at some point in order to allow us to experiment with it internally. I'll address some of the FIXMEs first though (mostly the hacks in the packager).
In the spirit of trunk based development, it would also be good to merge this even if it's not complete (see the "What's missing") rather than having a long running branch, so a focus on any blockers to that would be good (currently with the feature flag disabled there's mostly no impact except to some types, so it's a pretty safe change)
💻 Examples
🚨 Test instructions
✔️ PR Todo