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

135
Visualizações
pass parameter to variable which assigned require.context

When require.context of webpack is assigned to variable, how this variable can work receiveing parameter, like 'key'? For example,(in webpack document)

var context = require.context('components', true, /\.html$/);

// this 'context' variable receive parameter 'localA'
var context = require.context('locales', true, /\.json$/, 'lazy');
context('localeA').then((locale) => {
  // do something with locale
});

In this code, I can't understand why context variable can receive parameter 'localeA'. I looked in webpack documents, but I couldn't find how variable which is assigned to require.context can receive the parameter.

See another example...

var req = require.context("../someDir", true, /^(.*\.(js$))[^.]*$/igm);
req.keys().forEach(function(key){
    req(key);
});
// or just: req.keys().forEach(req)

webpack require every file in directory

the var req already returned context which fits conditions specified in parameters. then, why this code recall 'req(key)' with 'key' parameter which represents element of array(context) agian? Does this code mean => require.context(element of context = each file)? I can't understand this recall either..

  • In summary, my question is..
  1. How variable which is assignd to require.context can accept parameter. in webpack document, require.context can accept 4 parameter, =>
require.context(
  (directory: String),
  (includeSubdirs: Boolean) /* optional, default true */,
  (filter: RegExp) /* optional, default /^\.\/.*$/, any file */,
  (mode: String) /* optional, 'sync' | 'eager' | 'weak' | 'lazy' | 'lazy-once', default 'sync' */
);

but in the conde i can't understand, the parameter which is sent to variable(is assigned to 'require.context') is key (element of context array)

  1. why they recall require.cnotext in require.context.keys().foreach(), var req = require.context() already returned context array(files fit conditions),then why this code repeats require.context(key) in foreach() block?
var req = require.context("../someDir", true, /^(.*\.(js$))[^.]*$/igm);
// => return context array


req.keys().forEach(function(key){
    req(key);
// => means 'require.context(key)?
// why repeat require.context(each file)?
});
// or just: req.keys().forEach(req)

Please help me to understand this..

about 4 years ago · Juan Pablo Isaza
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