-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: Modify manifest entries for asset entrypoints (close #1765) #1774
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,10 @@ interface ManifestChunk { | |
dynamicImports?: string[] | ||
} | ||
|
||
function isEmptyChunk(chunk: OutputChunk): boolean { | ||
return !chunk.code || (chunk.code.length <= 1 && !chunk.code.trim()) | ||
} | ||
|
||
export function manifestPlugin(config: ResolvedConfig): Plugin { | ||
const manifest: Manifest = {} | ||
|
||
|
@@ -42,6 +46,15 @@ export function manifestPlugin(config: ResolvedConfig): Plugin { | |
} | ||
} | ||
|
||
function replaceFileWithAsset(chunk: OutputChunk) { | ||
const name = chunk.facadeModuleId ? getChunkName(chunk) : chunk.name | ||
const asset = Object.values(bundle).find( | ||
(otherChunk) => otherChunk.type === 'asset' && otherChunk.name == name | ||
) | ||
if (asset) chunk.fileName = asset.fileName | ||
return chunk | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 An alternative is to simply replace the There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? |
||
|
||
function createChunk(chunk: OutputChunk): ManifestChunk { | ||
const manifestChunk: ManifestChunk = { | ||
file: chunk.fileName | ||
|
@@ -83,6 +96,9 @@ export function manifestPlugin(config: ResolvedConfig): Plugin { | |
for (const file in bundle) { | ||
const chunk = bundle[file] | ||
if (chunk.type === 'chunk') { | ||
if (isEmptyChunk(chunk)) { | ||
replaceFileWithAsset(chunk) | ||
} | ||
manifest[getChunkName(chunk)] = createChunk(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.
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 forlength
.