I had a different solution due to my issue being a little different, I looked for an answer for a while but couldn't find one. Hopefully this may help someone.
My issue was that we had several applications deployed independently as different modules within a core UI. These had to be completely independently deployable within having any effect on the others.
My solution was to have the sub component applications wrapped as web pack libraries by setting these webpack properties:
libraryTarget: 'umd',
globalObject: 'this',
library: 'SubComponentName'
I think provided 2 entry points for the application based on it being accessed either directly or through a parent component within a separate application
class Library extends Component {
render() {
return (
< Provider store = {store} >< BrowserRouter>
< App isAccessDirect={this.props && this.props.isAccessDirect || false} roles={this.props.roles}>
</App>
< /BrowserRouter>< /Provider>
)
}
}
class Launcher extends Component {
render() {
return (
ReactDOM.render(
<Library isAccessDirect="true"/>,
document.getElementById('root')
)
)
}
}
Once this app is built I can access it directly in the index.html with
<script>
new Compression.Launcher().render();
</script>
Or if you wish to access the application via a separate host / component as was my requirement you can do so by using a combination of loadjs and react.
loadjs(['../sub/component/bundle.min.js'], 'loadSubComponent');
var subComponent = this.getUI('subComponentWrapperElement').get(0);
loadjs.ready('loadSubComponent', function() {
var roles = my.app.roles;
ReactDOM.render(
<SubComponentName.Library roles={roles}></SubComponentName.Library>,
subComponent
);
});
This can load in a react component in any type of javascript client side framework, in our case we used backbone within the wrapper application. The bundle.min.js was also located behind a reverse proxy but it could be located anywhere, its just essential that you load it in and await the load to finish, which loadjs was perfect for in this case. One final important bit of information was that destruction of the component was vital for ensuring a good user experience, as without we encountered a number of issues.
loadjs.reset();
var subComponent = this.getUI('subComponentWrapperElement').get(0);
ReactDOM.unmountComponentAtNode(subComponent);
So in a nut shell what I feel this provides over the other answers is a completely independently deployable suite of applications that can be completely framework agnostic.