VITE + REACT folder structure "public" vs "src/assets"?
As the title says I am looking for the best practice where should I store my static content eg.: png, font, svg, favico.
Public (Vite assets folder): you can reference the static files by this folder location without the need of "public" to be spcified.
src/assets (react assets folder): It is bundled together with other react files (a bit smaller size), also you can refer it as a module.
7 Replies
I follow the convention that is specified in their docs (depending on which library/ framework I am using) it makes sure Im not fighting something for no reason
In Astro I believe
src/assets
is for when you want to modify the image programatically in some way, whereas in public
you leave it as-isI spent hours to read not just the official docs but reddit, properly feeded AI and some youtube videos. Their official statement is contradictory. Vite suggests public folder as static assets folder, like wwwroot in dotNET. React follows the same with it's own assets folder:D
I have chosen the public folder since the outer scope context is Vite not React standalone but I am still unsure.
so one of those 2 things will end up building your app.
use that one.
Okey, thanks 🙂
I think that makes sense! As long as you have a logical reason and it builds I think you're good 🙂
I just checked and we have Vite plugins for image manipulation, optimisation etc... so it's also similar or even more If I take this into consideration.
https://github.com/ElMassimo/vite-plugin-image-presets
Thanks for your answer Vince 🙂