Last active
March 21, 2018 16:35
-
-
Save pmunin/ae8d24d68f239528adf73177265fa838 to your computer and use it in GitHub Desktop.
Javascript import all modules of 1st level subfolders (Webpack)
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
//gist url: https://gist.github.com/pmunin/ae8d24d68f239528adf73177265fa838 | |
var context = require.context('./', true, /(\.\/)[^/]+(\/)$/); | |
//regex to get all 1st level subfolders paths (e.g.: "./subFolder/", but not "./subFolder/subFolder/") | |
const subModules = {} | |
context.keys().forEach((filename)=>{ //e.g.: ./subFolder/ | |
const subModule = context(filename); //same as: import * as subModule from './subFolder/' | |
subModules[filename]=subModule; | |
}); | |
export default subModules |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment