Not loading files in files
Hello. I have my react-website. I used /dist because I am using react + vite. The problem is that I have files of images inside main image folder. As you can see on pictures. What are steps to build it to work?
9 Replies
https://github.com/Tom4sko/BuildsMarket-Web
tell me if it is private or public
Posting again here for visibility. The repo is now public. Project does use the github connect not manual upload
I made a fork of your repo (https://github.com/demosjarco/BuildsMarket-Web) and it's live here: https://buildsmarket-web-cf6.pages.dev (This is just for demo purposes, I'll be taking it down later this week)
By default the build configurations points to a finished directory of
/build
but the last few logs
show the content being created in /dist
insteadChanging the output directory to
/dist
allows it to build successfully on the next tryTo change this, go to the pages project >
Settings
> Builds & deployments
> Build configurations
> Edit Configurations
> Build output directory
and set it to dist
not build
but still i cant see the images in team section
when you look closely to team page there are empty images. It is caused because they are in a folderer inside main image folder
I think this is an error in e.g.
src/database/PartnerData.js
. The photo
properties in there reference ../src/images/
but I think they should be ../images/
yeah but ../images/ is not working even on my local
I tried to put folders inside public folder and still
idk how can my imports be bad
it is just ignoring folder inside folder
even though i checked .gitignore and there is nothing
it is live on git, but still cloudflare cant process it somehow
I've been looking at Vite documentation (interesting distraction), I think the issue was that the path strings were not being imported.
In
src/screens/DonateScreen.jsx
for example, paypalLogo
is being imported and that reference is being used for the src
. It seems this triggers the asset management and the src
gets adjusted appropriately during build.
Without the import, as is the case where those images are missing, the reference to e.g. {BuildersItem.photo}
is simply being treated as a string and results in exactly that string being output during the build.
If you put images inside public
, it looks like you should reference them using an absolute path, treating public
as the root. E.g. if you have public/images/BuildersImages/Hyyzounn.png
, the string you use in BuildersData.js
should be /images/BuildersImages/Hyyzounn.png
.
The part about using public
is here by the way:
https://vitejs.dev/guide/assets.html#the-public-directory