Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

111
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda