Skip to content

Instantly share code, notes, and snippets.

@jemsgit
Created May 24, 2022 07:11
Show Gist options
  • Save jemsgit/2dc13ec1b09c924ccb3133b37f79e83d to your computer and use it in GitHub Desktop.
Save jemsgit/2dc13ec1b09c924ccb3133b37f79e83d to your computer and use it in GitHub Desktop.
let path = require('path');
function requireDynamically(modulePath) {
modulePath = path.resolve('./', modulePath);
return eval(`require('${modulePath}');`); // Ensure Webpack does not analyze the require statement
}
module.exports = requireDynamically;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment