-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
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(html)!: support more asset sources #11138
Conversation
Moving to the 5.0 milestone as we don't have a way to opt-out of this feature if someone needs to. Either a dedicated API, sharing with |
Would I am really eager to have this feature as early as possible as it just makes Vite so much more suited for SSG. Not only image transformation as I brought up a few days ago (#11099) but also CSP hashes. Both of which are recommended for modern websites and currently missing in Vite whereas other SSG solutions support them like this eleventy blog theme. |
We can't ask the user to update their links to opt-out. The links should stay as is. We'd need some time to discuss the API before we can move forward with this. (Related discussion: #3533) |
What about making it opt in? Similar to assetsInclude, an optional config for the attribute strings you need to locate and parse assets in? |
+1 |
Would making a new configuration option for the Vite config file fix this issue? export interface UserConfig {
// ...
/**
* Configure which HTML tags and attributes to use as asset sources.
*/
assetSources?: AssetSourcesOptions
// ...
}
export interface AssetSourcesOptions {
[tag: string]: {
[attribute: string]: boolean
}
} Default configuration would be: (this matches what is currently present in the code) // ...
assetSources: {
audio: {src: false},
embed: {src: false},
img: {src: true, srcset: true},
input: {src: false},
object: {src: false},
source: {src: true, srcset: true},
track: {src: false},
video: {poster: true, src: true},
image: {href: true, 'xlink:href': true},
use: {href: true, 'xlink:href': true},
link: {href: true, imagesrcset: false},
meta: {content: false},
}
// ... I'm new to contributing to pull requests, so forgive me if I do/say something dumb. |
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 think it's a much cleaner implementation of finding asset sources in HTML than what is currently in the codebase.
Can't add the og:image yet due to vitejs/vite#11138 😔
Sorry for not getting back, this slipped through my notifications 😅 This would indeed be a solution too but ideally we want to keep the configuration internally until needed. In different news, in the last meeting we discussed that we would introduce I'm still (secretly) hoping we would support |
Dropping this off the milestone for now. We can revisit this in the next minor. Further context: #11854 (comment) |
Would love to see this landed. #7062 is very unexpected and feels like a bug. I can see how there's space for adding more build options. But treating |
Will need to wait for #18494 before I can properly rebase the code. Not sure if this will get into the next major though, but it's close to done |
getAttrKey(src) === 'srcset', | ||
/* useSrcSetReplacer */ false, |
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 realized the script tag src
is never going to be a srcset, so this can be false
This is now done. Compared to the initial implementation, I shrunk down the complexity of handled HTML elements list quite a lot. I realized we don't have to completely follow what
There may be actual reasons these were implemented in |
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.
LGTM 👍
It would be nice to mention it in the migration guide. That more attributes are now transformed and it can be excluded by |
/ecosystem-ci run |
📝 Ran ecosystem CI on
✅ ladle, laravel, marko, nuxt, previewjs, quasar, qwik, rakkas, vite-environment-examples, vite-plugin-pwa, vite-plugin-react, vite-plugin-react-swc, vite-plugin-svelte, vite-setup-catalogue, vitepress, vuepress |
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.
awesome work
Description
Support more tags to process as assets.
Close #7362
Close #5098
Supersedes and closes #7643 (There was a lot of conflicts that it's easier to start from scratch)
Additional context
What is the purpose of this pull request?
Before submitting the PR, please make sure you do the following
fixes #123
).