From e11bc43bed0bc9c2ad8315aea33c3b54c5140052 Mon Sep 17 00:00:00 2001 From: Taylor Smock Date: Mon, 12 Jun 2023 10:59:25 -0600 Subject: [PATCH] Use lazy loading for routes This reduces the main bundle size from 6.07 MB to 3.65 MB but increases overall application size from 14.04 MB to 14.18 MB. Most of the remainder of the main bundle size is from polyfills (2.35 MB) and libraries supporting localization (i18n). Signed-off-by: Taylor Smock --- frontend/src/routes.js | 508 ++++++++++++++++++++++++------ frontend/src/views/projectEdit.js | 2 +- 2 files changed, 418 insertions(+), 92 deletions(-) diff --git a/frontend/src/routes.js b/frontend/src/routes.js index 7208613b01..457a3a0244 100644 --- a/frontend/src/routes.js +++ b/frontend/src/routes.js @@ -1,110 +1,436 @@ -import { lazy } from 'react'; import { createBrowserRouter, createRoutesFromElements, Route } from 'react-router-dom'; import { Root } from './views/root'; -import { Home } from './views/home'; -import { AboutPage } from './views/about'; -import { LearnPage } from './views/learn'; -import { QuickstartPage } from './views/quickstart'; -import { UserDetail } from './views/userDetail'; -import { - UserProjectsPage, - ManageProjectsPage, - CreateProject, - ProjectsPage, - ProjectsPageIndex, - MoreFilters, - ProjectDetailPage, -} from './views/project'; import { Authorized } from './views/authorized'; -import { Login } from './views/login'; -import { Welcome } from './views/welcome'; -import { Settings } from './views/settings'; -import { ManagementPageIndex, ManagementSection } from './views/management'; -import { - ListOrganisations, - CreateOrganisation, - EditOrganisation, -} from './views/organisationManagement'; -import { OrganisationDetail } from './views/organisationDetail'; -import { OrganisationStats } from './views/organisationStats'; -import { MyTeams, ManageTeams, CreateTeam, EditTeam, TeamDetail } from './views/teams'; -import { ListCampaigns, CreateCampaign, EditCampaign } from './views/campaigns'; -import { ListInterests, CreateInterest, EditInterest } from './views/interests'; -import { ListLicenses, CreateLicense, EditLicense } from './views/licenses'; -import { Stats } from './views/stats'; -import { UsersList } from './views/users'; import { NotFound } from './views/notFound'; -import { SelectTask } from './views/taskSelection'; -import { MapTask, ValidateTask } from './views/taskAction'; -import { EmailVerification } from './views/verifyEmail'; -import { ProjectStats } from './views/projectStats'; -import { ContactPage } from './views/contact'; -import { SwaggerView } from './views/swagger'; -import { ContributionsPage, ContributionsPageIndex, UserStats } from './views/contributions'; -import { NotificationsPage } from './views/notifications'; import { FallbackComponent } from './views/fallback'; import { Redirect } from './components/redirect'; -const ProjectEdit = lazy(() => import('./views/projectEdit' /* webpackChunkName: "projectEdit" */)); export const router = createBrowserRouter( createRoutesFromElements( } ErrorBoundary={FallbackComponent}> - } /> - }> - } /> - } /> + { + const { Home } = await import('./views/home' /* webpackChunkName: "home" */); + return { Component: Home }; + }} /> + { + const { ProjectsPage } = await import( + './views/project' /* webpackChunkName: "project" */ + ); + return { Component: ProjectsPage }; + }} + > + { + const { ProjectsPageIndex } = await import( + './views/project' /* webpackChunkName: "project" */ + ); + return { Component: ProjectsPageIndex }; + }} + /> + { + const { MoreFilters } = await import( + './views/project' /* webpackChunkName: "project" */ + ); + return { Component: MoreFilters }; + }} + /> - } /> - } /> - } /> - } /> - } /> - } /> - } /> + { + const { ProjectDetailPage } = await import( + './views/project' /* webpackChunkName: "project" */ + ); + return { Component: ProjectDetailPage }; + }} + /> + { + const { SelectTask } = await import( + './views/taskSelection' /* webpackChunkName: "taskSelection" */ + ); + return { Component: SelectTask }; + }} + /> + { + const { MapTask } = await import( + './views/taskAction' /* webpackChunkName: "taskAction" */ + ); + return { Component: MapTask }; + }} + /> + { + const { ValidateTask } = await import( + './views/taskAction' /* webpackChunkName: "taskAction" */ + ); + return { Component: ValidateTask }; + }} + /> + { + const { ProjectStats } = await import( + './views/projectStats' /* webpackChunkName: "projectStats" */ + ); + return { Component: ProjectStats }; + }} + /> + { + const { OrganisationStats } = await import( + './views/organisationStats' /* webpackChunkName: "organisationStats" */ + ); + return { Component: OrganisationStats }; + }} + /> + { + const { OrganisationDetail } = await import( + './views/organisationDetail' /* webpackChunkName: "organisationDetail" */ + ); + return { Component: OrganisationDetail }; + }} + /> } /> - } /> - } /> - } /> - } /> - }> - } /> - } /> - } /> - } /> + { + const { LearnPage } = await import('./views/learn' /* webpackChunkName: "learn" */); + return { Component: LearnPage }; + }} + /> + { + const { QuickstartPage } = await import( + './views/quickstart' /* webpackChunkName: "quickstart" */ + ); + return { Component: QuickstartPage }; + }} + /> + { + const { AboutPage } = await import('./views/about' /* webpackChunkName: "about" */); + return { Component: AboutPage }; + }} + /> + { + const { ContactPage } = await import('./views/contact' /* webpackChunkName: "contact" */); + return { Component: ContactPage }; + }} + /> + { + const { ContributionsPageIndex } = await import( + './views/contributions' /* webpackChunkName: "contributions" */ + ); + return { Component: ContributionsPageIndex }; + }} + > + { + const { UserStats } = await import( + './views/contributions' /* webpackChunkName: "contributions" */ + ); + return { Component: UserStats }; + }} + /> + { + const { ContributionsPage } = await import( + './views/contributions' /* webpackChunkName: "contributions" */ + ); + return { Component: ContributionsPage }; + }} + /> + { + const { UserProjectsPage } = await import( + './views/project' /* webpackChunkName: "project" */ + ); + return { Component: UserProjectsPage }; + }} + /> + { + const { MyTeams } = await import('./views/teams' /* webpackChunkName: "teams" */); + return { Component: MyTeams }; + }} + /> - } /> - } /> + { + const { UserDetail } = await import( + './views/userDetail' /* webpackChunkName: "userDetail" */ + ); + return { Component: UserDetail }; + }} + /> + { + const { NotificationsPage } = await import( + './views/notifications' /* webpackChunkName: "notifications" */ + ); + return { Component: NotificationsPage }; + }} + /> } /> - } /> - } /> - } /> - } /> - }> - } /> - } /> - } /> - } /> - } /> - } /> - } /> - } /> - } /> - } /> - } /> - } /> - } /> - } /> - } /> - } /> - } /> - } /> - } /> - } /> - } /> + { + const { Login } = await import('./views/login' /* webpackChunkName: "login" */); + return { Component: Login }; + }} + /> + { + const { Welcome } = await import('./views/welcome' /* webpackChunkName: "welcome" */); + return { Component: Welcome }; + }} + /> + { + const { Settings } = await import('./views/settings' /* webpackChunkName: "settings" */); + return { Component: Settings }; + }} + /> + { + const { EmailVerification } = await import( + './views/verifyEmail' /* webpackChunkName: "verifyEmail" */ + ); + return { Component: EmailVerification }; + }} + /> + { + const { ManagementSection } = await import( + './views/management' /* webpackChunkName: "management" */ + ); + return { Component: ManagementSection }; + }} + > + { + const { ManagementPageIndex } = await import( + './views/management' /* webpackChunkName: "management" */ + ); + return { Component: ManagementPageIndex }; + }} + /> + { + const { Stats } = await import('./views/stats' /* webpackChunkName: "stats" */); + return { Component: Stats }; + }} + /> + { + const { ListOrganisations } = await import( + './views/organisationManagement' /* webpackChunkName: "organisationManagement" */ + ); + return { Component: ListOrganisations }; + }} + /> + { + const { CreateOrganisation } = await import( + './views/organisationManagement' /* webpackChunkName: "organisationManagement" */ + ); + return { Component: CreateOrganisation }; + }} + /> + { + const { EditOrganisation } = await import( + './views/organisationManagement' /* webpackChunkName: "organisationManagement" */ + ); + return { Component: EditOrganisation }; + }} + /> + { + const { ManageTeams } = await import('./views/teams' /* webpackChunkName: "teams" */); + return { Component: ManageTeams }; + }} + /> + { + const { UsersList } = await import('./views/users' /* webpackChunkName: "users" */); + return { Component: UsersList }; + }} + /> + { + const { CreateTeam } = await import('./views/teams' /* webpackChunkName: "teams" */); + return { Component: CreateTeam }; + }} + /> + { + const { EditTeam } = await import('./views/teams' /* webpackChunkName: "teams" */); + return { Component: EditTeam }; + }} + /> + { + const { ListCampaigns } = await import( + './views/campaigns' /* webpackChunkName: "campaigns" */ + ); + return { Component: ListCampaigns }; + }} + /> + { + const { CreateCampaign } = await import( + './views/campaigns' /* webpackChunkName: "campaigns" */ + ); + return { Component: CreateCampaign }; + }} + /> + { + const { EditCampaign } = await import( + './views/campaigns' /* webpackChunkName: "campaigns" */ + ); + return { Component: EditCampaign }; + }} + /> + { + const { CreateProject } = await import( + './views/project' /* webpackChunkName: "project" */ + ); + return { Component: CreateProject }; + }} + /> + { + const { ProjectEdit } = await import( + './views/projectEdit' /* webpackChunkName: "projectEdit" */ + ); + return { Component: ProjectEdit }; + }} + /> + { + const { ManageProjectsPage } = await import( + './views/project' /* webpackChunkName: "project" */ + ); + return { Component: ManageProjectsPage }; + }} + /> + { + const { ListInterests } = await import( + './views/interests' /* webpackChunkName: "interests" */ + ); + return { Component: ListInterests }; + }} + /> + { + const { EditInterest } = await import( + './views/interests' /* webpackChunkName: "interests" */ + ); + return { Component: EditInterest }; + }} + /> + { + const { CreateInterest } = await import( + './views/interests' /* webpackChunkName: "interests" */ + ); + return { Component: CreateInterest }; + }} + /> + { + const { CreateLicense } = await import( + './views/licenses' /* webpackChunkName: "licenses" */ + ); + return { Component: CreateLicense }; + }} + /> + { + const { ListLicenses } = await import( + './views/licenses' /* webpackChunkName: "licenses" */ + ); + return { Component: ListLicenses }; + }} + /> + { + const { EditLicense } = await import( + './views/licenses' /* webpackChunkName: "licenses" */ + ); + return { Component: EditLicense }; + }} + /> - } /> - } /> + { + const { TeamDetail } = await import('./views/teams' /* webpackChunkName: "teams" */); + return { Component: TeamDetail }; + }} + /> + { + const { SwaggerView } = await import('./views/swagger' /* webpackChunkName: "swagger" */); + return { Component: SwaggerView }; + }} + /> } /> } /> , diff --git a/frontend/src/views/projectEdit.js b/frontend/src/views/projectEdit.js index 1b88c52457..fb992c5ca9 100644 --- a/frontend/src/views/projectEdit.js +++ b/frontend/src/views/projectEdit.js @@ -62,7 +62,7 @@ const doesValidationTeamNotExist = (teams, validationPermission) => teams.filter((team) => team.role === 'VALIDATOR').length === 0 && teams.filter((team) => team.role === 'PROJECT_MANAGER').length === 0; -export default function ProjectEdit() { +export function ProjectEdit() { const { id } = useParams(); useSetTitleTag(`Edit project #${id}`); const [errorLanguages, loadingLanguages, languages] = useFetch('system/languages/');