0๐
I found another solution, I used require.context
:
const getConfig = require.context(
'../data',
true,
/\/[\w-]+\/config\.js$/,
)
getConfig.keys().forEach(fileName => {
const file = require(`../data${fileName.substring(1)}`).default
console.log(file)
})
Source:stackexchange.com