Next.js Discord

Discord Forum

I need an unimported image to be copied over into the .next/static/media directory, how do I do that

Unanswered
Siamese Crocodile posted this in #help-forum
Open in Discord
Siamese CrocodileOP
I need another version of my website's logo to be copied over into the build of my static website. The reason I need it copied over is I am referencing it in my emails so I need the image to be displayed. How can I get an unused image in the public folder to be copied over to the build? Using next 13.4

5 Replies

if you have public/image.png, then you can always access it at /image.png whether or not you import it anywhere
Siamese CrocodileOP
@joulev Hey Joulev, that is not the case when performing a build. Once built if an image isn't imported then it isn't included in the build and the build is what exists at runtime in the docker container, not the source public folder.
@Siamese Crocodile <@484037068239142956> Hey Joulev, that is not the case when performing a build. Once built if an image isn't imported then it isn't included in the build and the build is what exists at runtime in the docker container, not the source public folder.
oh i see what you mean, i've always assumed that the public directory is handled by the build process but it turns out it isn't. there are now a few ways to go:
* modify the docker configuration to copy the public directory over as well, before running next start
* import the image anyway, import "./path/to/image.png";, even when you don't need it
the second way requires you to find a way to know the image url though because it won't be a nice url but something like this /_next/static/media/image.79ffbedc.png
Siamese CrocodileOP
I ended up importing it into a component and hiding it so it never loads for the end-user, lol