Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

109
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!