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.