I’m making a project with Vue3 + Vite and trying to set an adaptive src for the img:
<img :src="`@img/map_icons/${ currentMap.title }_icon.png`">
In vite.config i’ve created the alias:
'@img': resolve(__dirname, 'src/shared/assets/img')
But website doesn’t load my img and giving an error:
GET http://localhost:5173/@img/map_icons/ancient_icon.png 404 (Not Found)
The only way i find to do it correctly is by using relative src:
<img :src="`./../../shared/assets/img/map_icons/${ currentMap.title }_icon.png`">
So how can i set the src with using alias?
2
Answers
This can be done with
tsconfig.json
orjsconfig.json
. Createtsconfig.json
orjsconfig.json
file in your project’s root directory and add following fieldsYou can resolve all of your needed images as URLs (remember they all will be included in the build) and find an appropriate URL: