-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
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
fix: Modify manifest entries for asset entrypoints (close #1765) #1774
Conversation
) | ||
if (asset) chunk.fileName = asset.fileName | ||
return chunk | ||
} |
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.
Didn't want to optimize it until we discuss the approach.
We should use an approach similar to chunkToEmittedAssetsMap
, where we index the corresponding asset in a Map
as we process the chunks, so that we can efficiently retrieve them here.
An alternative is to simply replace the fileName
in the chunk beforehand, but I'm not sure if the processing order would allow that.
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.
Since multiple chunks can have the same name, this can result in wrong mapping if two entry assets have the same name. e.g. logo.svg
and logo.png
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.
In this case we would be comparing resolved names, which include the file extension, and entrypoint assets always include the file extension in their name, so there wouldn't be a collision, correct?
@@ -19,6 +19,10 @@ interface ManifestChunk { | |||
dynamicImports?: string[] | |||
} | |||
|
|||
function isEmptyChunk(chunk: OutputChunk): boolean { | |||
return !chunk.code || (chunk.code.length <= 1 && !chunk.code.trim()) |
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.
In the cases I observed, code
was always \n
, so there's potential for simplification here.
Didn't want to run trim()
on a large string, hence the check for length
.
882d354
to
b8c51de
Compare
See #1765 (comment) - I believe it's better suited as a custom plugin instead of handling this in the manifest, which strictly assumes entries are js chunks and assets are just emitted files that belongs to chunks. |
Gotcha, wasn't aware of this design decision, since the manifest listed asset entrypoints prior to beta 51. |
Description 📖
This pull request is an attempt to fix #1765, by modifying the manifest output for asset entrypoints.
The manifest output now ignores empty chunks, and replaces their
file
with an actual asset path (if one exists).As a result, the regression is fixed, and obtaining the resource URL for generic entries (JS/CSS/images) becomes simpler since
file
is always the source of truth for the resource path, regardless of the entry type.Before
But the fingerprinted file is actually
assets/logo.41cff365.svg
, which is not in the manifest, but is in the output dir.After
Background 📜
When adding a non-JS and non-CSS entrypoint, such as an
.svg
, in the manifest entry:file
points to an empty JS chunk, and it can't be used to resolve the filePrior to beta 51
file
had the resolved path to the fingerprinted file.Manifest in Beta 51/52
Entire Manifest after changes in this PR
Have in mind that it doesn't affect the format for non-entrypoint CSS in the manifest.