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

114
Visualizações
Access webpack require.context from dev server

I have a webpack dev config that I use to server a mocked backend with express. Something like this example form DevServer Docs:

module.exports = {
  // ...
  devServer: {
    setupMiddlewares: (middlewares, devServer) => {
      if (!devServer) {
        throw new Error('webpack-dev-server is not defined');
      }

      devServer.app.get('/setup-middleware/some/path', (_, response) => {
        response.send('setup-middlewares option GET');
      });
    },
  },
};

But instead of directly serving there I load and initialize another file that will attempt to search for every file with 'mock.js' in the name and load them. For that I plan to use require.context since it is a webpack feature. But everytime I try to do this I get that context is undefined.

I try to load them like this:

const context = require.context('../src/', true, /\.mock\.js$/);
const mocks = context.keys().map(context);

Is there a way to implement this feature back in? (Or at least have an alternative) I have been looking around but it seems that not many people have had my problem.

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