H
H
hannyto11112021-06-09 13:45:32
Vue.js
hannyto1111, 2021-06-09 13:45:32

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

1 answer(s)
A
Aetae, 2021-06-10
@hannyto1111

requiredoes not "take pictures from a folder", requireprocesses pictures loader'omand 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`);nameimg './img/*.png',loader'ом
loader'ыdata:uriimgs
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 publiccopied to the resulting folder as they are and are available /name.pngwithout require, just through the usual htmland css.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question