Skip to content

Instantly share code, notes, and snippets.

@mitchell-garcia
Created February 2, 2018 03:58
Show Gist options
  • Save mitchell-garcia/8c2b40046d2943fe381502dee6b0fc4c to your computer and use it in GitHub Desktop.
Save mitchell-garcia/8c2b40046d2943fe381502dee6b0fc4c to your computer and use it in GitHub Desktop.
const modules = {};
let tmpModule;
function requireAll(r) {
r.keys().forEach(function (moduleName) {
tmpModule = r(moduleName);
if (!tmpModule.default) {
throw new Error(`Module not correctly exported. Excepted Vuex Module definition but got: ${tmpModule.default} for module: ${moduleName}`);
}
const fileName = moduleName.replace(/(\.\/|\.js)/g, '').split('/');
const name = fileName[fileName.length - 1];
modules[name] = tmpModule.default;
});
}
requireAll(require.context('./directory', true, /.js$/));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment