Answer the question
In order to leave comments, you need to log in
How to require a file from the public folder?
Hello, to add some file from src, I can use for example require(`./assets/items/${name}.png`);
But how can I use a file from the public folder ...
Answer the question
In order to leave comments, you need to log in
require
does not "take pictures from a folder", require
processes pictures loader'om
and returns the result. A static result that gets into the bundle. - does not mean "take a picture by name from the folder at runtime ", it means " at compile time, take all the pictures with a mask , process them, get a static link for each , and put them in the bundle". by default, small pictures are turned into strings, and large ones are transferred to a folder and renamed with a hash, returning the path. But this is by default, and so they are able to do a lot of all sorts of magic. Essence:
require(`./img/${name}.png`);
name
img
'./img/*.png',
loader'ом
loader'ы
data:uri
imgs
you will not pick up new pictures that were not there during the assembly.
But this is not necessary, the pictures in the folder are public
copied to the resulting folder as they are and are available /name.png
without require
, just through the usual html
and css
.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question