Replies: 2 comments
-
This is a fundamental issue on the web in general that is often solved with build tooling, but with Lit I think it boils down to what you're building. Are you building a component that is:
Reusable element meant to be distributedIn this case, depending on the situation you can always ask the user to input the location of the resource e.g. if you're making a If you're shipping an asset that is not configurable in your package you can use const assetUrl = new URL('./local/asset/location.png', import.meta.url);
class MyEl extends LitElement {
render() {
return html`
<img src=${assetUrl.href}>
`;
}
} Finally there is also base64 as you suggested. Specific to your appIf this is the case, the most common solution here is to just link to the file directly since you will have control over routing, file system, and asset locations. |
Beta Was this translation helpful? Give feedback.
-
Developing for Lit with Vite has been awesome for many reasons ... and it supports static imports out-of-the-box. Here's a snippet from my code that sets up an
Then, in a component, I can write:
When Vite builds the site for production, these are replaced with the correct relative URLs for your deployment location. Here's the documentation on static assets with Vite: Finally, here's a Lit Starter Kit that's already setup w/ Vite. You can drop it in a directory and play with it: Enjoy! |
Beta Was this translation helpful? Give feedback.
-
If yours component have some static asset (like svg background img, etc...) then how do you load that images?
When i developing i use just static url, but in production use cdn url. (ex: img src="/static/asset1.svg")
It is trivial but it annoy me.
What is best practice? just base64 encoding? '-'..
Beta Was this translation helpful? Give feedback.
All reactions