Created
November 7, 2015 00:43
-
-
Save frostney/bd1092e27ea3de299458 to your computer and use it in GitHub Desktop.
Trying to figure out a way to load directories through webpack programmatically
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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