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
Enable specifying implicit dependencies when emitting chunks #3606
Conversation
Thank you for your contribution! ❤️You can try out this pull request locally by installing Rollup via
or load it into the REPL: |
At the moment, the new property is Maybe when emitting, we call the property |
Codecov Report
@@ Coverage Diff @@
## master #3606 +/- ##
==========================================
+ Coverage 96.36% 96.39% +0.02%
==========================================
Files 181 182 +1
Lines 6168 6210 +42
Branches 1814 1820 +6
==========================================
+ Hits 5944 5986 +42
Misses 111 111
Partials 113 113
Continue to review full report at Codecov.
|
Another point I keep stumbling about is how to handle implicit dependant modules that are not part of the graph. We already considered the case where the id does not exist, but another case is where the module is empty or otherwise has no relevant side-effects. In that case, it is not assigned to any chunk and it is unclear which chunk should be loaded before. One way to handle this would be to throw an error here as well because by the implicit dependencies, there would be no way to reach that chunk. Alternatively, we could ignore missing implicit dependant modules and if there are none in the end, we promote the chunk to a regular entry point? Any thoughts @LarsDenBakker? Note that this should not be a problem if a chunks solely depends on entry modules because for those, a chunk is always created, but I need to check. Another point that is still missing is that our chunks do not yet respect entry signatures. |
After some consideration I think I want to throw errors for now. Replacing an error with a non-error logic can always be done in a non-breaking change, the alternative is more difficult. |
ae0b74c
to
6ca9118
Compare
Thanks a lot for this! Sorry I haven't had any time to test this yet, will try it out soon. |
8f70e98
to
d32a4a1
Compare
This is now fully working, all that is missing is some documentation |
e847763
to
771a51e
Compare
771a51e
to
9f21174
Compare
Tried it out, it works exactly the way I was hoping for 👍 |
Cool! I also added some documentation now, would be nice if someone could read it and see if it is sufficiently clear. Suggestions of course welcome! |
…e all implicit dependencies
This PR contains:
Are tests included?
Breaking Changes?
List any relevant issue numbers:
Resolves #3574
Description
This will enable chunk emitters to specify that an otherwise independent chunk will only be loaded if at least one of a list of modules has been loaded before, allowing Rollup to create fewer chunks. The logic will be the same as if the chunk was only reachable via dynamic import from any of the specified module ids. A good use-case could be when parsing an HTML file for scripts as entry points—subsequent scripts can rely on previous scripts having loaded and can import shared dependencies directly from the chunks of the previous scripts.
The API of
this.emitFile
will be extended to acceptIf there are one or more module ids in
implicitlyLoadedAfterOneOf
, then this chunk will assume that at least one of the chunks containing those modules is already in memory, basically exactly as if each of those modules contained a dynamic import of the newly emitted chunk.This will be reflected in
this.getModuleInfo
as well as the bundle
Things to do and clarify:
implicitlyLoadedAfterOneOf
modules is not part of the output graph, either because it is not found, it is empty, or it is only reachable via a tree-shaken dynamic import? Do we want to throw in all cases, or ignore those modules up to the point where our module is promoted to a regular entry point?implicitlyLoadedAfterOneOf
should respect both the user-definedpreserveEntrySignatures
option as well as thepreserveSignature
emission optionimplicitlyLoadedAfterOneOf
entriesimplicitlyLoadedAfterOneOf
entries. In that case, we merge those entries. Could be combined with the previous test.