Skip to content

Instantly share code, notes, and snippets.

@davidsonsns
Last active June 1, 2018 15:50
Show Gist options
  • Save davidsonsns/29f71f29ac7715da354ad09ad21393af to your computer and use it in GitHub Desktop.
Save davidsonsns/29f71f29ac7715da354ad09ad21393af to your computer and use it in GitHub Desktop.
Require every file in a directory
/**
* 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