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
Add rule for chunk-download-size-limits #203
Comments
Thanks for the issue!
Let's start from rule parameters: export type Params = {
byName: Array<{name: string | RegExp; limit: number; useCompressed: boolean}>
}; So, here is a pseudo-code of the rule implementation: const chunkDownloadSizeLimits: WebpackRule<Params> = (params, data, api): void => {
api.setRuleDescriptor(...);
for (const item of params.byName) {
const targetChunks = getTargetChunksFromDataWithParams(data, params); // collect chunks by name or regexp (you could use jora or pure js here)
for (const chunk of targetChunks) {
const diff = isChunkSizeOk(chunk, item); // check chunk size by the item props
if (diff) {
api.message('Oh, no!', {
filename: data.files[0].name,
compilation: chunk.compilation.hash,
related: [{ type: 'chunk', id: chunk.id }],
});
}
}
}
};
export default chunkDownloadSizeLimits;
Yep
Chunks origins is more accuracy to get chunk relations from webpack stats |
Thanks for your detailed answer.
One more thing, the |
Yep. Every module includes chunks-property. You could find all the modules you need (e.g. by module name) and then collect chunks from the chunks-property.
Yes, one module could belong to several chunks. That's why chunks-property is an array
Seems like there is a bug in webpack stats (see #168 for more info). Do you have concerns with using origins to build chunk graph? |
Is your feature request related to a problem? Please describe.
I try to limit the size of the critical path our application needs on ci.
However, our application is running in a host application(SPA), that serves several other 'apps' on the same page.
So
@statoscope/webpack/entry-download-size-limits
no longer suits us, cause we are no longer initial chunks.Is there any other way to provide this kind of rule, that limits the size of the chunks that critical rendering path need?
Describe the solution you'd like
A clear and concise description of what you want to happen.
One way to achieve this is to specify the chunk that the rendering codes are in (like a designated webpack chunks name), then find all its parent chunks.
Describe alternatives you've considered
Another way of doing it is just to find all the chunks that the critical rendering path needs, simply just by its module name.
However, a module might be duplicated in different chunks, I am not very clear on how to implement this way(But isn't that rendering code should only appear once in the final builds?).
Additional context
I tried to implement a simple version of it by myself, following the custom rule guide.
But get stuck in compilations API in
WebpackRule<Params> = (ruleParams, data, api): void
of date object.Although in my
stats.json
, theparents
property exists for every chunk, I can't get it from 'data.compilations[0].chunks[someIndex].parents'.Looking into the source code,
I found in the source code, the chunk's parent has been set to empty and relink by chunks' origin, which is not in ours
stats.json
jora
by simply looking into the demo. (Is there any tutorial on this subject?) .Would you accept the rule's pr withoutjora
?The text was updated successfully, but these errors were encountered: