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

fix(manifest): include assets referenced in html #14657

Merged
merged 1 commit into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion packages/vite/src/node/plugins/html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -826,7 +826,11 @@ export function buildHtmlPlugin(config: ResolvedConfig): Plugin {
)
// resolve asset url references
result = result.replace(assetUrlRE, (_, fileHash, postfix = '') => {
return toOutputAssetFilePath(this.getFileName(fileHash)) + postfix
const file = this.getFileName(fileHash)
if (chunk) {
chunk.viteMetadata!.importedAssets.add(cleanUrl(file))
}
return toOutputAssetFilePath(file) + postfix
})

result = result.replace(publicAssetUrlRE, (_, fileHash) => {
Expand Down
5 changes: 5 additions & 0 deletions playground/assets/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,11 @@ <h2>Image Src Set</h2>
/>
</div>

<h2>HTML only asset</h2>
<div>
<img src="./nested/html-only-asset.jpg" alt="" />
</div>

<h2>SVG Fragments</h2>
<div>
<img
Expand Down
Binary file added playground/assets/nested/html-only-asset.jpg
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tiny nit: could we use an svg so it's smaller?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My next PR will make SVG be inline.
But I can use a new SVG and reduce the inlineSize now, but this requires a new config test because the default one is already increase to 8kb (why I used ~12kb one)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah ok if it's specifically to pass the 8kb limit, and there's no existing files to use I'm fine with it then. No need to change 👍

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.