Is it possible to make webpack load another module based on some context information?
For example I've two versions of my React application: desktop and mobile
In my index.js I decide which application to load:
if (isMobile()) {
loadMobile().then(({default: App}) => render(App))
}
Now I would like to reuse some modules, but some I would like to override it. So by default it should load index.js, but if the context isMobile and next to the index.js a mobile.js file exists, it should load the mobile variant.
components/
Button/
index.js
mobile.js
In the mobile context, webpack should load mobile.js instead of index.js
I could't find anything that I could use to solve it, any ideas?
PS: I've already created an issue on github, it also demonstrates the problem and what I want to achieve even better: