Wardan
Question about image tag and svgs in production
Hello I am working in Nuxt3 and am fairly new to web dev and very new to Nuxt3
I am trying to learn how to properly use a svg that will work in production.
Here is the code that was in my page before moving to a component, it worked in dev and production
I have many of these so I moved it to a component, once moving it to a component the svg's broke and no longer loaded.
so I just changed it to a more static URL (instead of ~/assets) as shown below
However, this only works in dev and not production
I then tried to changed the img src to just to try it in production (or dev) but it did not work and it would show that path if I inspected
I googled and search for a solution and did not find one. maybe I am not understanding something properly
I tried this chatgpt solution
It worked in dev but not production, when inspecting I'd get this URL
I then tried a second chat gpt solution which works, but feels very hacky and I'd like to learn how to properly handle this
The second working chatgpt solution was to create a map of the images and use them in the component via the key
I have not tried sticking the svg's in the public folder but I also do want them to accessible at a static URL which is why I havent tried this.
Some insight/explanation on how to properly do this would be fantastic and appreciated.
15 replies