Created
May 18, 2021 17:15
-
-
Save EmilyRosina/2e66d087bd3ce7585e299a9415ec19c2 to your computer and use it in GitHub Desktop.
Imports several modules dynamically
This file contains hidden or 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
const requireModule = require.context('.', false, /^\.\/Cy.+\.js$/) | |
const modules = requireModule.keys().reduce((modules, fileName) => { | |
const moduleName = fileName.replace(/(\.\/|\.js)/g, '') | |
return { ...modules, [moduleName]: requireModule(fileName).default } | |
}, {}) | |
export const components = Object.keys(modules) | |
export default modules |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment