I am currently trying to load a variable array of modules with Webpack. I've found this link: webpack can not require variable ,the request of a dependency is an expression but it doesn't seem to work for me.
In my project I've got a module inside my node_modules folder. The entry point of the module is called index.js.
Here's the basic structure:
| app
+---app.js
| js
+---gen.js
| node_modules
  +---sample_module_1
  |   +---index.js
  +-sample-module_2
      +---index.js
| webpack.config.js
In future I'd like to add new modules. Therefore I tried following approach:
//app.js
var modules = [
  "sample_module_1",
  "sample_module_2"
]
for(var i = 0; i < modules.length; i++) {
  require(modules[i] + "/index.js");
}
But Webpack doesn't seem to find the module. I've tried adding a resolveLoader to the webpack.config.js file:
//webpack.config.js
var path = require('path');
module.exports = {
  entry: './app/app.js',
  output: {
    filename: 'gen.js',
    path: path.resolve(__dirname, 'js')
  },
  resolveLoader: {
    modules: ["node_modules"],
    extensions: ['*', '.js']
  }
};
Still, Webpack is not able to find the module.
I've also tried the suggestions on https://webpack.github.io/docs/context.html but still no results.
Any suggestions?