fix: Add some code splitting for PWA build (#937)

* fix: Add some code splitting for PWA build

* Fix missing files
This commit is contained in:
Erik Ziegler authored and GitHub committed 2019-09-26 11:35:13 +02:00
1 parent edb86fad55
commit 89380353d2
15 files changed
+236 -30

No files matched your search

@@ -0,0 +1,37 @@
/**
* We use this component to leverage "Code Splitting"
*
* Link: https://serverless-stack.com/chapters/code-splitting-in-create-react-app.html
*/
import React, { Component } from 'react';
export default function asyncComponent(importComponent) {
class AsyncComponent extends Component {
constructor(props) {
super(props);
this.state = {
component: null,
};
}
async componentDidMount() {
// Add dynamically loaded component to state
const { default: component } = await importComponent();
this.setState({
component: component,
});
}
render() {
const C = this.state.component;
// Render the loaded component, or null
return C ? <C {...this.props} /> : null;
}
}
return AsyncComponent;
}
+3 -1
View File
@@ -1,7 +1,9 @@
import OHIFCornerstoneViewport from './OHIFCornerstoneViewport.js';
import asyncComponent from './asyncComponent.js';
import commandsModule from './commandsModule.js';
import toolbarModule from './toolbarModule.js';
const OHIFCornerstoneViewport = asyncComponent(() => import( /* webpackChunkName: "OHIFCornerstoneViewport" */ './OHIFCornerstoneViewport.js'));
/**
*
*/