Caveat: I haven’t actually used this tool I am about to mention.
I was looking through Elm 2021, a year in review and came across elm-embed, which it seems may be usable in this situation. Instead of modifying the JS into an import statement and then relying on Vite to transform those into URLs, this could directly embed the URLs. The downside is that you would need to actually know how an image will be converted into a URL (if the image ends up with a hashed file name, this may not work).
At work, we have passed asset base URLs into Elm as flags and then (optimistically) computed the asset URLs for things like icons, which feels …meh.