I currently have this set up with Vue and Webpack:
const imports = {
foo: require('./folder/foo.yml'),
bar: require('./folder/bar.yml')
}
Is there a way to add more keys + values with this structure dynamically, where the key equals the file name without the file extension?
Please see if this helps.
const testFolder = './tests/';
const fs = require('fs');
const imports = {}
fs.readdirSync(testFolder).forEach(file => {
const filekey = file.split('.').slice(0, -1).join('.');
imports[filekey] = require('./tests/' + file);
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With