Add lazy loading support.

This commit is contained in:
Paulo Gustavo Veiga 2022-08-15 20:00:49 -07:00
parent b48d55ebca
commit ac6d6357c8
2 changed files with 122 additions and 128 deletions

View File

@ -1,7 +1,6 @@
import React, { ReactElement } from 'react'; import React, { ReactElement, Suspense } from 'react';
import { IntlProvider } from 'react-intl'; import { IntlProvider } from 'react-intl';
import { Route, Switch, Redirect, BrowserRouter as Router } from 'react-router-dom'; import { Route, Switch, Redirect, BrowserRouter as Router } from 'react-router-dom';
import RegistrationSuccessPage from './components/registration-success-page';
import ForgotPasswordSuccessPage from './components/forgot-password-success-page'; import ForgotPasswordSuccessPage from './components/forgot-password-success-page';
import RegistationPage from './components/registration-page'; import RegistationPage from './components/registration-page';
import LoginPage from './components/login-page'; import LoginPage from './components/login-page';
@ -11,14 +10,15 @@ import { Provider } from 'react-redux';
import { QueryClient, QueryClientProvider } from 'react-query'; import { QueryClient, QueryClientProvider } from 'react-query';
import { theme } from './theme'; import { theme } from './theme';
import AppI18n, { Locales } from './classes/app-i18n'; import AppI18n, { Locales } from './classes/app-i18n';
import MapsPage from './components/maps-page';
import CssBaseline from '@mui/material/CssBaseline'; import CssBaseline from '@mui/material/CssBaseline';
import { ThemeProvider, Theme, StyledEngineProvider } from '@mui/material/styles'; import { ThemeProvider, Theme, StyledEngineProvider } from '@mui/material/styles';
import ReactGA from 'react-ga4'; import ReactGA from 'react-ga4';
import EditorPage from './components/editor-page';
import AppConfig from './classes/app-config'; import AppConfig from './classes/app-config';
import withSessionExpirationHandling from './components/HOCs/withSessionExpirationHandling'; import withSessionExpirationHandling from './components/HOCs/withSessionExpirationHandling';
const EditorPage = React.lazy(() => import('./components/editor-page'));
const RegistrationSuccessPage = React.lazy(() => import('./components/registration-success-page'));
const MapsPage = React.lazy(() => import('./components/maps-page'));
declare module '@mui/styles/defaultTheme' { declare module '@mui/styles/defaultTheme' {
// eslint-disable-next-line @typescript-eslint/no-empty-interface // eslint-disable-next-line @typescript-eslint/no-empty-interface
@ -29,10 +29,9 @@ declare module '@mui/styles/defaultTheme' {
ReactGA.initialize([ ReactGA.initialize([
{ {
trackingId: AppConfig.getGoogleAnalyticsAccount(), trackingId: AppConfig.getGoogleAnalyticsAccount(),
} },
]); ]);
const queryClient = new QueryClient({ const queryClient = new QueryClient({
defaultOptions: { defaultOptions: {
queries: { queries: {
@ -62,34 +61,28 @@ const App = (): ReactElement => {
<Route exact path="/"> <Route exact path="/">
<Redirect to="/c/login" /> <Redirect to="/c/login" />
</Route> </Route>
<Route path="/c/login" <Route path="/c/login" component={LoginPage} />
component={LoginPage} <Route path="/c/registration" component={RegistationPage} />
/> <Route path="/c/registration-success" component={RegistrationSuccessPage} />
<Route path="/c/forgot-password" component={ForgotPasswordPage} />
<Route path="/c/forgot-password-success" component={ForgotPasswordSuccessPage} />
<Route <Route
path="/c/registration" exact
component={RegistationPage} path="/c/maps/"
/> >
<Route <Suspense fallback={<div>Loading...</div>}>
path="/c/registration-success" <MapsPage/>
component={RegistrationSuccessPage} </Suspense>
/> </Route>
<Route
path="/c/forgot-password"
component={ForgotPasswordPage}
/>
<Route
path="/c/forgot-password-success"
component={ForgotPasswordSuccessPage}
/>
<Route
exact path="/c/maps/"
component={withSessionExpirationHandling(MapsPage)}
/>
<Route exact path="/c/maps/:id/edit"> <Route exact path="/c/maps/:id/edit">
<Suspense fallback={<div></div>}>
<EnhacedEditorPage isTryMode={false} /> <EnhacedEditorPage isTryMode={false} />
</Suspense>
</Route> </Route>
<Route exact path="/c/maps/:id/try"> <Route exact path="/c/maps/:id/try">
<Suspense fallback={<div></div>}>
<EnhacedEditorPage isTryMode={true} /> <EnhacedEditorPage isTryMode={true} />
</Suspense>
</Route> </Route>
</Switch> </Switch>
</Router> </Router>

View File

@ -38,6 +38,7 @@ module.exports = {
}, },
optimization: { optimization: {
usedExports: true, usedExports: true,
chunkIds: 'named',
splitChunks: { splitChunks: {
cacheGroups: { cacheGroups: {
vendors: { vendors: {