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

Ability to collect chunk info before or during renderchunk #3519

Closed
LarsDenBakker opened this issue Apr 28, 2020 · 8 comments · Fixed by #4543 or #4549
Closed

Ability to collect chunk info before or during renderchunk #3519

LarsDenBakker opened this issue Apr 28, 2020 · 8 comments · Fixed by #4543 or #4549

Comments

@LarsDenBakker
Copy link
Contributor

Feature Use Case

I am writing a plugin that needs to do work in renderChunk, but in order to do this it has to know more about the rest of the chunk graph. For example for a given chunk's dynamic imports, it has to know their static imports. Right now I can access the dynamic imported filenames, but I have no way to acces the chunk info for this.

I tried a lot of different things, for example the augmentChunkHash hook gives some minimal chunk information, but it's not enough.

I can use generateBundle as a general escape hatch, but the big downside here is that it runs after any chunk optimizations such as babel and terser.

Feature Proposal

I don't know enough about the rollup internals, so I'm just throwing out some ideas from a plugin writer's perspective. Of course I'm happy to learn about methods available in the existing hooks I may have overlooked!

In order of preference:

  • Add a bundle or chunks parameter to the renderChunk hook containing information about the other chunks. (probably with less info than in generateBundle)
  • Add a hook that runs before renderChunk giving information about the chunking graph (again with less info)
  • Add a this.getChunkInfo method so that we can get the chunk based on the dynamic import id
@tivac
Copy link
Contributor

tivac commented Apr 28, 2020

Does this.getModuleInfo() work in renderChunk and get you the info you need?

@lukastaegert
Copy link
Member

lukastaegert commented Apr 28, 2020

Good question indeed. Could you outline what exactly it is you need to know about the chunks? I.e. give us a rough sketch what you want to do with the chunking information?

@LarsDenBakker
Copy link
Contributor Author

This is related to #3520. After grouping together translations, I want to preload translations parallel to loading a page. But also to implement something like #3009

This means that for a given chunk I need to know which dynamic imports it has, and be able to get information about the dynamic import's chunks.

chunk.dynamicImports gives the dynamically imported files, but there is no way to get to the chunk data from there. this.getModuleInfo() is not sufficient here because it gives info about modules, not chunks.

@lukastaegert
Copy link
Member

One problem: We do not know the chunk names yet in renderChunk, and you would need those to do that. The problem here is hashing. I have some ideas how to address this together, but it will be a larger project (I want to tackle in the near future, though). Basically part of the idea is that chunks will have a pseudo name where the hash is replaced with a placeholder first; this would already be available in renderChunk. Then the hashing will happen after renderChunk with the placeholders in the files; last, only the placeholders will be replaced.

@lukastaegert
Copy link
Member

This is now included in #4543

@rollup-bot
Copy link
Collaborator

This issue has been resolved via #4543 as part of rollup@3.0.0-7. Note that this is a pre-release, so to test it, you need to install Rollup via npm install rollup@3.0.0-7 or npm install rollup@beta. It will likely become part of a regular release later.

@rollup-bot
Copy link
Collaborator

This issue has been resolved via #4543 as part of rollup@3.0.0-8. Note that this is a pre-release, so to test it, you need to install Rollup via npm install rollup@3.0.0-8 or npm install rollup@beta. It will likely become part of a regular release later.

@rollup-bot
Copy link
Collaborator

This issue has been resolved via #4543 as part of rollup@3.0.0. You can test it via npm install rollup.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants