troygoode / node-require-directory

Recursively iterates over specified directory, requiring each file, and returning a nested hash structure containing those libraries.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Can't support webpack!

weineel opened this issue · comments

Will the support of webpack be added?

That would be really nice, this lib breaks packages that require it, if using webpack.

You can use require.context to get the same behaviour:

let context = require.context('../some/directory', false, /onlyinclude.js$/);
context.keys().forEach(filename => {
	let obj = context(filename);
	obj.someFuntion();
});

This works with webpack.

For anyone else looking for a solution for webpack, you can use this babel plugin:

https://github.com/vihanb/babel-plugin-wildcard

Benefit is it's all done compile-time 🎉
Works great for me 👍