0

I'm trying to load some arbitrary modules during runtime which are not available during build time. Think of plugins which are only required at runtime. So something like:

require(plugin_dir + '/plugins.js')

needs to be loaded but webpack complains rightfully that this module is not available. How can I make this work?

I tried SystemJS to trick webpack but it figured out what I'm trying to accomplish and fails.

three
  • 8,262
  • 3
  • 35
  • 39
  • Looks like I can use https://github.com/ezze/node-require-wrapper to achieve just that. Need more testing to see if it actually works as I expect. – three May 01 '18 at 12:18

1 Answers1

0

In the end I used https://github.com/ezze/node-require-wrapper

It works like that:

Webpack config file:

module.exports = {
  // ...
  module: {
      rules: {
          // ...
      },
      noParse: /require-wrapper/
  }
}

Then in your code you can use it like this:

var nodeRequire = require('require-wrapper');
var helloModulePath = path.resolve(__dirname, 'dynamic/hello.js');
three
  • 8,262
  • 3
  • 35
  • 39