-
-
Notifications
You must be signed in to change notification settings - Fork 385
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
feat: filter chunk assets #655
Conversation
Fixes #652 ? |
@@ -187,8 +188,13 @@ class ChunkExtractor { | |||
this.outputPath = outputPath || this.stats.outputPath | |||
this.statsFile = statsFile | |||
this.entrypoints = Array.isArray(entrypoints) ? entrypoints : [entrypoints] | |||
this.filter = filter || Boolean |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's use a less generic name on this
scope. For example filterChunk
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right, I made the change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also renamed the option as it makes its purpose more explicit.
I don't think so. I didn't want to mess with loadable-stats.json as my intent was only to prevent serving hmr chunks but the stats could potentially serve other purposes. |
Don't know why the ci failed on the last commit. |
@theKashey if you prefer that the filter occurs in the webpack plugin (exclude chunks from stats file) let me know. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
@theKashey I'm having a problem with stats.json. When generated, it does not contain hmr chunks (obviously) and the |
Yeah, probably you should take the original stats (as it's now generated from a real project) and add some "extra" fields in runtime to test, or filter some "normal" chunks, as it does not have test |
I had my initial usecase so much on my mind that I didn't think about it! |
3be70dc
to
d1dca8c
Compare
👀 ..... |
😅 I don't know what's wrong. I run the commands
Any idea ? |
@cahnory - it's just dead a little. Strangely there is no travis here, and these tests are the only really important thing. |
Anyway I can help here? |
The real problem here is a "new" undocumented feature, which implementation is still on the user. |
This is not what I understood from our previous exchanges. In this case, if I understand correctly, it seems unsolvable and maybe we should close this PR. |
Decisions change in time. That's ok.
The internal changes are legit and I would like to have them. I am just thinking that we should, at least for now, put The lazy maintainer rule is simple - if you can not expose something - do not, or you will have to maintain it forever (and you are lazy by definition). |
I understand, no problem. Just that by doing this way this PR should be closed in favor of a new one which maybe just add a cookbook recipe to the doc. The way I do it right now is just by filtering const filterHmr = (list) =>
list.filter(
(element) =>
!element.props.src?.match(/wps-hmr\.[^.\\/]+$/) &&
!element.props.href?.match(/wps-hmr\.[^.\\/]+$/),
); I just wasn't satisfied with having to check the file names rather than their stats (and extra loops but they are negligible). |
That's why it's still good to have the majority of this PR built-in into loadable with the correct behavior working out of the box |
Oh I see, I completely misunderstood what you were saying. Sorry. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Summary
In development, when doing SSR with HMR you don't want the hmr related files to be linked by the served html. The
filter
option in addition to the newinfo
property added to chunk assets make it possible.I favored this approach rather than an "excludeHmrFiles" type option as it could serve other purposes and remain relevant even if hmr is abandoned in the future.
Test plan
Using webpack with hmr enabled, instanciate your
ChunkExtractor
like :All files relative to hmr (suffixed with "-wps-hmr" by default) should be excluded from the results of
getScriptTags
,getScriptElements
,…