I could spend an hour explaining my code and everything I've tried, but the absolute basics is this:
Onload, my script creates buttons for each type in the types array:
for(let type of types) {
let btn = document.createElement('button');
btn.innerHTML = `<img class="type-icon" src="img/types/${type.name}.svg"> `;
I have a folder called img with a folder called types inside it where I store 18 "type" icons, for "fire", "water", etc.
Is there a way of doing this dynamically with parcel JS?
Currently, the images are all missing. I've tried importing * but that doesn't seem to work with Parcel. I've tried requiring them dynamically, also doesn't work. I understand that Parcel probably looks through for the names of files to import and in the generated scripts replaces those names with the file names... Is there a way to do this with static assets? I had the same problem with my json files and it took me a while to figure out that I needed to remove all of my fetch code and import them. Is there a way to keep the same file names with Parcel? It doesn't seem like there is, but if it's not combining the files anyway I don't see why not...