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:
parent
edb86fad55
commit
89380353d2
@ -1,3 +1,4 @@
|
|||||||
|
const webpack = require('webpack');
|
||||||
const merge = require('webpack-merge');
|
const merge = require('webpack-merge');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const webpackCommon = require('./../../../.webpack/webpack.commonjs.js');
|
const webpackCommon = require('./../../../.webpack/webpack.commonjs.js');
|
||||||
@ -34,5 +35,10 @@ module.exports = (env, argv) => {
|
|||||||
libraryExport: 'default',
|
libraryExport: 'default',
|
||||||
filename: pkg.main,
|
filename: pkg.main,
|
||||||
},
|
},
|
||||||
|
plugins: [
|
||||||
|
new webpack.optimize.LimitChunkCountPlugin({
|
||||||
|
maxChunks: 1,
|
||||||
|
}),
|
||||||
|
],
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
37
extensions/cornerstone/src/asyncComponent.js
Normal file
37
extensions/cornerstone/src/asyncComponent.js
Normal file
@ -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;
|
||||||
|
}
|
||||||
@ -1,7 +1,9 @@
|
|||||||
import OHIFCornerstoneViewport from './OHIFCornerstoneViewport.js';
|
import asyncComponent from './asyncComponent.js';
|
||||||
import commandsModule from './commandsModule.js';
|
import commandsModule from './commandsModule.js';
|
||||||
import toolbarModule from './toolbarModule.js';
|
import toolbarModule from './toolbarModule.js';
|
||||||
|
|
||||||
|
const OHIFCornerstoneViewport = asyncComponent(() => import( /* webpackChunkName: "OHIFCornerstoneViewport" */ './OHIFCornerstoneViewport.js'));
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
const webpack = require('webpack');
|
||||||
const merge = require('webpack-merge');
|
const merge = require('webpack-merge');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const webpackCommon = require('./../../../.webpack/webpack.commonjs.js');
|
const webpackCommon = require('./../../../.webpack/webpack.commonjs.js');
|
||||||
@ -34,5 +35,10 @@ module.exports = (env, argv) => {
|
|||||||
libraryExport: 'default',
|
libraryExport: 'default',
|
||||||
filename: pkg.main,
|
filename: pkg.main,
|
||||||
},
|
},
|
||||||
|
plugins: [
|
||||||
|
new webpack.optimize.LimitChunkCountPlugin({
|
||||||
|
maxChunks: 1,
|
||||||
|
}),
|
||||||
|
],
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
37
extensions/dicom-html/src/asyncComponent.js
Normal file
37
extensions/dicom-html/src/asyncComponent.js
Normal file
@ -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;
|
||||||
|
}
|
||||||
@ -1,5 +1,11 @@
|
|||||||
|
import asyncComponent from './asyncComponent.js';
|
||||||
import OHIFDicomHtmlSopClassHandler from './OHIFDicomHtmlSopClassHandler.js';
|
import OHIFDicomHtmlSopClassHandler from './OHIFDicomHtmlSopClassHandler.js';
|
||||||
import OHIFDicomHtmlViewport from './OHIFDicomHtmlViewport.js';
|
|
||||||
|
const OHIFDicomHtmlViewport = asyncComponent(() =>
|
||||||
|
import(
|
||||||
|
/* webpackChunkName: "OHIFDicomHtmlViewport" */ './OHIFDicomHtmlViewport.js'
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
/**
|
/**
|
||||||
@ -12,5 +18,5 @@ export default {
|
|||||||
},
|
},
|
||||||
getSopClassHandlerModule() {
|
getSopClassHandlerModule() {
|
||||||
return OHIFDicomHtmlSopClassHandler;
|
return OHIFDicomHtmlSopClassHandler;
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
const webpack = require('webpack');
|
||||||
const merge = require('webpack-merge');
|
const merge = require('webpack-merge');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const webpackCommon = require('./../../../.webpack/webpack.commonjs.js');
|
const webpackCommon = require('./../../../.webpack/webpack.commonjs.js');
|
||||||
@ -34,5 +35,10 @@ module.exports = (env, argv) => {
|
|||||||
libraryExport: 'default',
|
libraryExport: 'default',
|
||||||
filename: pkg.main,
|
filename: pkg.main,
|
||||||
},
|
},
|
||||||
|
plugins: [
|
||||||
|
new webpack.optimize.LimitChunkCountPlugin({
|
||||||
|
maxChunks: 1
|
||||||
|
})
|
||||||
|
]
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,10 +1,7 @@
|
|||||||
import React, { Component } from 'react';
|
import React, { Component } from 'react';
|
||||||
import ReactResizeDetector from 'react-resize-detector';
|
import ReactResizeDetector from 'react-resize-detector';
|
||||||
import { api } from 'dicom-microscopy-viewer';
|
|
||||||
import debounce from 'lodash.debounce';
|
import debounce from 'lodash.debounce';
|
||||||
|
|
||||||
const microscopyViewer = api.VLWholeSlideMicroscopyImageViewer;
|
|
||||||
|
|
||||||
class DicomMicroscopyViewport extends Component {
|
class DicomMicroscopyViewport extends Component {
|
||||||
state = {
|
state = {
|
||||||
error: null,
|
error: null,
|
||||||
@ -56,9 +53,12 @@ class DicomMicroscopyViewport extends Component {
|
|||||||
}
|
}
|
||||||
return Promise.all(promises);
|
return Promise.all(promises);
|
||||||
})
|
})
|
||||||
.then(metadata => {
|
.then(async metadata => {
|
||||||
metadata = metadata.filter(m => m);
|
metadata = metadata.filter(m => m);
|
||||||
|
|
||||||
|
const { api } = await import(/* webpackChunkName: "dicom-microscopy-viewer" */ 'dicom-microscopy-viewer');
|
||||||
|
const microscopyViewer = api.VLWholeSlideMicroscopyImageViewer;
|
||||||
|
|
||||||
this.viewer = new microscopyViewer({
|
this.viewer = new microscopyViewer({
|
||||||
client: dicomWebClient,
|
client: dicomWebClient,
|
||||||
metadata,
|
metadata,
|
||||||
|
|||||||
37
extensions/dicom-microscopy/src/asyncComponent.js
Normal file
37
extensions/dicom-microscopy/src/asyncComponent.js
Normal file
@ -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;
|
||||||
|
}
|
||||||
@ -1,5 +1,11 @@
|
|||||||
|
import asyncComponent from './asyncComponent.js';
|
||||||
import DicomMicroscopySopClassHandler from './DicomMicroscopySopClassHandler.js';
|
import DicomMicroscopySopClassHandler from './DicomMicroscopySopClassHandler.js';
|
||||||
import DicomMicroscopyViewport from './DicomMicroscopyViewport.js';
|
|
||||||
|
const DicomMicroscopyViewport = asyncComponent(() =>
|
||||||
|
import(
|
||||||
|
/* webpackChunkName: "DicomMicroscopyViewport" */ './DicomMicroscopyViewport.js'
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
const webpack = require('webpack');
|
||||||
const merge = require('webpack-merge');
|
const merge = require('webpack-merge');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const webpackCommon = require('./../../../.webpack/webpack.commonjs.js');
|
const webpackCommon = require('./../../../.webpack/webpack.commonjs.js');
|
||||||
@ -34,5 +35,10 @@ module.exports = (env, argv) => {
|
|||||||
libraryExport: 'default',
|
libraryExport: 'default',
|
||||||
filename: pkg.main,
|
filename: pkg.main,
|
||||||
},
|
},
|
||||||
|
plugins: [
|
||||||
|
new webpack.optimize.LimitChunkCountPlugin({
|
||||||
|
maxChunks: 1,
|
||||||
|
}),
|
||||||
|
],
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
37
extensions/vtk/src/asyncComponent.js
Normal file
37
extensions/vtk/src/asyncComponent.js
Normal file
@ -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;
|
||||||
|
}
|
||||||
@ -1,9 +1,13 @@
|
|||||||
import OHIFVTKViewport from './OHIFVTKViewport.js';
|
import asyncComponent from './asyncComponent.js';
|
||||||
import commandsModule from './commandsModule.js';
|
import commandsModule from './commandsModule.js';
|
||||||
import toolbarModule from './toolbarModule.js';
|
import toolbarModule from './toolbarModule.js';
|
||||||
// This feels weird
|
// This feels weird
|
||||||
// import loadLocales from './loadLocales';
|
// import loadLocales from './loadLocales';
|
||||||
|
|
||||||
|
const OHIFVTKViewport = asyncComponent(() =>
|
||||||
|
import(/* webpackChunkName: "OHIFVTKViewport" */ './OHIFVTKViewport.js')
|
||||||
|
);
|
||||||
|
|
||||||
const vtkExtension = {
|
const vtkExtension = {
|
||||||
/**
|
/**
|
||||||
* Only required property. Should be a unique value across all extensions.
|
* Only required property. Should be a unique value across all extensions.
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
const webpack = require('webpack');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const merge = require('webpack-merge');
|
const merge = require('webpack-merge');
|
||||||
const webpackCommon = require('./../../../.webpack/webpack.commonjs.js');
|
const webpackCommon = require('./../../../.webpack/webpack.commonjs.js');
|
||||||
@ -54,6 +55,9 @@ module.exports = (env, argv) => {
|
|||||||
template: `${PUBLIC_DIR}/html-templates/${HTML_TEMPLATE}`,
|
template: `${PUBLIC_DIR}/html-templates/${HTML_TEMPLATE}`,
|
||||||
filename: 'index.html',
|
filename: 'index.html',
|
||||||
}),
|
}),
|
||||||
|
new webpack.optimize.LimitChunkCountPlugin({
|
||||||
|
maxChunks: 1
|
||||||
|
})
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
@ -7,13 +7,7 @@ import { CSSTransition } from 'react-transition-group';
|
|||||||
import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
import { ViewerbaseDragDropContext } from '@ohif/ui';
|
import { ViewerbaseDragDropContext } from '@ohif/ui';
|
||||||
import { SignoutCallbackComponent } from 'redux-oidc';
|
import { SignoutCallbackComponent } from 'redux-oidc';
|
||||||
// import asyncComponent from './components/AsyncComponent.js'
|
import asyncComponent from './components/AsyncComponent.js';
|
||||||
import IHEInvokeImageDisplay from './routes/IHEInvokeImageDisplay.js';
|
|
||||||
import ViewerRouting from './routes/ViewerRouting.js';
|
|
||||||
import ViewerLocalFileData from './connectedComponents/ViewerLocalFileData.js';
|
|
||||||
import StudyListRouting from './studylist/StudyListRouting.js';
|
|
||||||
import StandaloneRouting from './routes/StandaloneRouting.js';
|
|
||||||
import CallbackPage from './routes/CallbackPage.js';
|
|
||||||
import NotFound from './routes/NotFound.js';
|
import NotFound from './routes/NotFound.js';
|
||||||
import { Bar, Container } from './components/LoadingBar/';
|
import { Bar, Container } from './components/LoadingBar/';
|
||||||
import './OHIFStandaloneViewer.css';
|
import './OHIFStandaloneViewer.css';
|
||||||
@ -24,18 +18,32 @@ import './theme-tide.css';
|
|||||||
import AppContext from './context/AppContext';
|
import AppContext from './context/AppContext';
|
||||||
|
|
||||||
// Dynamic Import Routes (CodeSplitting)
|
// Dynamic Import Routes (CodeSplitting)
|
||||||
// const IHEInvokeImageDisplay = asyncComponent(() =>
|
const IHEInvokeImageDisplay = asyncComponent(() =>
|
||||||
// import('./routes/IHEInvokeImageDisplay.js')
|
import(
|
||||||
// )
|
/* webpackChunkName: "IHEInvokeImageDisplay" */ './routes/IHEInvokeImageDisplay.js'
|
||||||
// const ViewerRouting = asyncComponent(() => import('./routes/ViewerRouting.js'))
|
)
|
||||||
// const StudyListRouting = asyncComponent(() =>
|
);
|
||||||
// import('./studylist/StudyListRouting.js')
|
const ViewerRouting = asyncComponent(() =>
|
||||||
// )
|
import(/* webpackChunkName: "ViewerRouting" */ './routes/ViewerRouting.js')
|
||||||
// const StandaloneRouting = asyncComponent(() =>
|
);
|
||||||
// import('./routes/StandaloneRouting.js')
|
const StudyListRouting = asyncComponent(() =>
|
||||||
// )
|
import(
|
||||||
// const CallbackPage = asyncComponent(() => import('./CallbackPage.js'))
|
/* webpackChunkName: "StudyListRouting" */ './studylist/StudyListRouting.js'
|
||||||
//
|
)
|
||||||
|
);
|
||||||
|
const StandaloneRouting = asyncComponent(() =>
|
||||||
|
import(
|
||||||
|
/* webpackChunkName: "StandaloneRouting" */ './routes/StandaloneRouting.js'
|
||||||
|
)
|
||||||
|
);
|
||||||
|
const CallbackPage = asyncComponent(() =>
|
||||||
|
import(/* webpackChunkName: "CallbackPage" */ './routes/CallbackPage.js')
|
||||||
|
);
|
||||||
|
const ViewerLocalFileData = asyncComponent(() =>
|
||||||
|
import(
|
||||||
|
/* webpackChunkName: "ViewerLocalFileData" */ './connectedComponents/ViewerLocalFileData.js'
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
const reload = () => window.location.reload();
|
const reload = () => window.location.reload();
|
||||||
|
|
||||||
@ -188,10 +196,14 @@ class OHIFStandaloneViewer extends Component {
|
|||||||
classNames="fade"
|
classNames="fade"
|
||||||
unmountOnExit
|
unmountOnExit
|
||||||
onEnter={() => {
|
onEnter={() => {
|
||||||
this.setState({ isLoading: true });
|
this.setState({
|
||||||
|
isLoading: true,
|
||||||
|
});
|
||||||
}}
|
}}
|
||||||
onEntered={() => {
|
onEntered={() => {
|
||||||
this.setState({ isLoading: false });
|
this.setState({
|
||||||
|
isLoading: false,
|
||||||
|
});
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{match === null ? (
|
{match === null ? (
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user