How to use transformIndexHtml to transform app.html
?
#8269
Replies: 7 comments 3 replies
-
transformIndexHtml isn't supported by sveletkit at the moment. You can do it at buildtime for prerendered pages via hooks.server.js |
Beta Was this translation helpful? Give feedback.
-
I'm curious what your usecase for it is? We've never bothered implementing it because there's not much you can do with it and it's difficult to use with SSR, but if there were a compelling usecase perhaps we could find a way to solve it |
Beta Was this translation helpful? Give feedback.
-
@benmccann another usecase with transformIndexHtml that I came across today: https://github.com/ZhongxuYang/vite-plugin-version-mark This can still be done with virtual module, but getting everything done within the plugin is obviously better. Hope this will be put under the roadmap in the future |
Beta Was this translation helpful? Give feedback.
-
@benmccann and another use case: The very useful (and popular) vite-plugin-webfont-dl, that will download and configure web fonts automatically and inject them as a style tag into the index.html using that hook: feat-agency/vite-plugin-webfont-dl#38. |
Beta Was this translation helpful? Give feedback.
-
We're developing SPA applications time to time, and the fact that
The headache:
Basically I want to do this: /** @returns {import('vite').Plugin} */
export default function myPlugin() {
return {
name: 'my-plugin',
buildStart: {
order: 'post',
handler() {
// Generate favicons
}
},
transformIndexHtml: {
order: 'post',
handler() {
// Return all favicons
return [
{
tag: 'link',
attrs: {
rel: 'icon',
type: 'image/png',
href: 'path-to-favicon.png'
}
}
];
}
}
};
} |
Beta Was this translation helpful? Give feedback.
-
I think this plugin: https://github.com/josh-hemphill/vite-plugin-favicon would work quite nicely if Looking at the competition: I believe Next.js is doing a great job by eliminating the tedious task of setting up proper favicons almost entirely through the use of filename conventions. However, I would be happy if everything could be resolved with a simple plugin like the one mentioned above. Considering favicons as a fundamental feature with a significant variance in implementation, I believe this is something that should be taken seriously by the maintainers, as it something virtually every user runs into sooner or later and it would be a great addition to improve everyone's dx. |
Beta Was this translation helpful? Give feedback.
-
I tried josh-hemphill/vite-plugin-favicon but not working with sveltekit. |
Beta Was this translation helpful? Give feedback.
-
I am writing a Vite plugin, and I notice that
transformIndexHtml
is never called when using that plugin with SvelteKit. Is there a hook in Vite plugin that I can use to transformapp.html
?I prefer not to do the transformation in
hooks.server.js
, as I want this to be done once in build time, but I cannot find the hook I need right now.Beta Was this translation helpful? Give feedback.
All reactions