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

View File

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