11

I'm building an app that can load various modules (other bundles generated by different webpack configs) on demand. The BaseModule is responsible for knowing when to load which bundle and exports some default classes like BaseUtils. The module itself is not aware of all the possible modules/bundles it may need to load.

TestModule is one of those modules that is loaded on demand at runtime by the BaseModule, and TestModule wants to use BaseUtils.

The question is: Is it possible to require('basemodule/BaseUtils') in TestModule, which has its own webpack.config.js file, with BaseModule listed as external? That is, is there a way to let the generated testmodule bundle reuse the modules available in the generated basemodule bundle? Or does BaseModule neccesarily need to be exported to global variable?

Flion
  • 10,468
  • 13
  • 48
  • 68

1 Answers1

0

Note: Just a suggestion. I did not try this.

One way i think of is to bundle all other modules (TestModule) first and bundle your app which has BaseModule next. By this, TestModule bundle would be available in place when BaseModule is bundled. And TestModule bundle file should be available in the BaseModule's folder as webpack needs this when BaseModule is bundled. So your TestModule's webpack.config would have output path pointing to some folder under BaseModule's src folder.

Note: BaseUtils should be a CommonChunk because it is required by TestModule as well as BaseModule.

Thaadikkaaran
  • 5,088
  • 7
  • 37
  • 59
  • 1
    thanks for your answer but this is not an option for me since many modules will be created over time by different people after the basemodule is completed. – Flion Nov 09 '16 at 15:43