Skip to content

Instantly share code, notes, and snippets.

@frostney
Created November 7, 2015 00:43
Show Gist options
  • Save frostney/bd1092e27ea3de299458 to your computer and use it in GitHub Desktop.
Save frostney/bd1092e27ea3de299458 to your computer and use it in GitHub Desktop.
Trying to figure out a way to load directories through webpack programmatically
module.exports = function(folder, regex) {
if (folder == null) {
folder = './';
}
if (regex == null) {
regex = /\.(js|json|jsx)$/;
}
var req = require.context(folder, false, regex);
return req.keys().reduce(function(obj, name) {
obj[name] = req(name);
return obj;
}, {});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment