Skip to content

Instantly share code, notes, and snippets.

@jaksm
Created January 18, 2019 11:59
Show Gist options
  • Save jaksm/7f0824d67314705b5d8c023b699f3c44 to your computer and use it in GitHub Desktop.
Save jaksm/7f0824d67314705b5d8c023b699f3c44 to your computer and use it in GitHub Desktop.
Bulk import and export folder contents
var imports = {};
function importAll(r) {
r.keys().forEach(key => {
const module = r(key);
const name = key.split("./")[1].split(".")[0];
imports[name] = module.default;
});
}
importAll(require.context("./", true, /\.jsx$/));
module.exports = imports;
@jaksm
Copy link
Author

jaksm commented Jan 18, 2019

make src/.env file with contents: NODE_PATH=src, and you can do import { ComponentName } from "components" anywhere in your project

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment