11
votes

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?

1
This interests me as well. I am having a similar questionDimitris Karagiannis
Can you please share your App structure which includes BaseModule as well as TestModule?Thaadikkaaran

1 Answers

0
votes

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.