Last active
June 1, 2018 15:50
-
-
Save davidsonsns/29f71f29ac7715da354ad09ad21393af to your computer and use it in GitHub Desktop.
Require every file in a directory
This file contains hidden or 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
/** | |
* Baseaded in this issue | |
* @link https://github.com/webpack/webpack/issues/625 | |
*/ | |
import set from 'lodash/set'; | |
import trimStart from 'lodash/trimStart'; | |
const context = require.context('src/assets'); | |
const obj = {}; | |
context.keys().forEach(function(key) { | |
const k = trimStart(key, '.') | |
.split('/') | |
.filter(e => e); | |
set(obj, k, context(key)); | |
}); | |
export default obj |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment