Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

128
Visualizações
Importing all files from folder and putting them into an array with webpack require.context

So I looked at the docs for webpack, and I'm pretty sure that require.context is what I need to put all my images from a folder in an array.

In the folder "Perruet" I've got three jpg images.

By doing exactly what the doc say:

const cache = {};

function importAll(r) {
    
  r.keys().forEach((key) => (cache[key] = r(key)));

}

importAll(require.context('./img/Perruet', false, /\.jpg$/));


console.log("photo", cache) 

The console.log give me this result: enter image description here

What I need is the "default" value of the image that would give me the path to my image, but I can't get this value. Can someone help me to retrieve this value?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

    const cache1 = {

};

function importProjets(r) {

r.keys().forEach((key) => (cache1[key] = r(key)));

}

importProjets(require.context('./img/projets',true,/\.jpg$/));





console.log(cache1)
let vals1 = Object.values(cache1);
console.log(vals1);

let projectArray = [];
let projetsImg = [];
let empty=[];

export {projectArray};
function createArrayProjet(){
for (let i = 0; i < 20; i++){

projetsImg.push(vals1[i].default)
}
projectArray.push(projetsImg);
console.log("projectArrayMiddle",projectArray);

projetsImg=empty;


for (let i = 20; i < vals1.length; i++){

projetsImg.push(vals1[i].default)
}
projectArray.push(projetsImg);


}



createArrayProjet();
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda