diff --git a/angular-client/src/app/app-routing.module.ts b/angular-client/src/app/app-routing.module.ts index 6ef5e9f0..7dae9216 100644 --- a/angular-client/src/app/app-routing.module.ts +++ b/angular-client/src/app/app-routing.module.ts @@ -1,15 +1,4 @@ -import { NgModule } from '@angular/core'; -import { RouterModule, Routes } from '@angular/router'; -import { BmsDebugPageComponent } from 'src/pages/bms-debug-page/bms-debug-page.component'; -import { BmsSegmentViewComponent } from 'src/pages/bms-debug-page/bms-segment-view/bms-segment-view.component'; -import { CameraPageComponent } from 'src/pages/camera-page/camera-page.component'; -import CarCommandComponent from 'src/pages/car-command-page/car-command.component'; -import ChargingPageComponent from 'src/pages/charging-page/charging-page.component'; -import EfusesPageComponent from 'src/pages/efuses-page/efuses-page.component'; -import FaultPageComponent from 'src/pages/fault-page/fault-page.component'; -import GraphPageComponent from 'src/pages/graph-page/graph-page.component'; -import LandingPageComponent from 'src/pages/landing-page/landing-page.component'; -import MapComponent from 'src/pages/map/map.component'; +import { Routes } from '@angular/router'; import { Segment } from 'src/utils/bms.utils'; const landingRoute = () => `/landing`; @@ -38,25 +27,52 @@ export const appRoutes = { efusesRoute }; -// Routes should be defined carefully in accordance with the appRoutes -const routes: Routes = [ - { path: 'landing', component: LandingPageComponent }, - { path: 'graph', component: GraphPageComponent }, +// Lazy-loaded routes: each page is split into its own chunk to reduce initial bundle size (#199). +export const routes: Routes = [ + { + path: 'landing', + loadComponent: () => import('src/pages/landing-page/landing-page.component') + }, + { + path: 'graph', + loadComponent: () => import('src/pages/graph-page/graph-page.component') + }, { path: '', redirectTo: appRoutes.landingRoute(), pathMatch: 'full' }, - { path: 'map', component: MapComponent }, - { path: 'charging', component: ChargingPageComponent }, - { path: 'bms', component: BmsDebugPageComponent }, - // NOTE: paramaterized routes should be even more carefully defined in accordance with the appRoutes - { path: 'bms/segment/:id', component: BmsSegmentViewComponent }, - { path: 'faults', component: FaultPageComponent }, - { path: 'faults/fault-graph', component: GraphPageComponent }, - { path: 'camera', component: CameraPageComponent }, - { path: 'commands', component: CarCommandComponent }, - { path: 'efuses', component: EfusesPageComponent } + { + path: 'map', + loadComponent: () => import('src/pages/map/map.component') + }, + { + path: 'charging', + loadComponent: () => import('src/pages/charging-page/charging-page.component') + }, + { + path: 'bms', + loadComponent: () => import('src/pages/bms-debug-page/bms-debug-page.component').then((m) => m.BmsDebugPageComponent) + }, + { + path: 'bms/segment/:id', + loadComponent: () => + import('src/pages/bms-debug-page/bms-segment-view/bms-segment-view.component').then((m) => m.BmsSegmentViewComponent) + }, + { + path: 'faults', + loadComponent: () => import('src/pages/fault-page/fault-page.component') + }, + { + path: 'faults/fault-graph', + loadComponent: () => import('src/pages/graph-page/graph-page.component') + }, + { + path: 'camera', + loadComponent: () => import('src/pages/camera-page/camera-page.component').then((m) => m.CameraPageComponent) + }, + { + path: 'commands', + loadComponent: () => import('src/pages/car-command-page/car-command.component') + }, + { + path: 'efuses', + loadComponent: () => import('src/pages/efuses-page/efuses-page.component') + } ]; - -@NgModule({ - imports: [RouterModule.forRoot(routes)], - exports: [RouterModule] -}) -export class AppRoutingModule {} diff --git a/angular-client/src/main.ts b/angular-client/src/main.ts index a9256ce8..1e28bb38 100644 --- a/angular-client/src/main.ts +++ b/angular-client/src/main.ts @@ -6,69 +6,15 @@ import { provideClientHydration, BrowserModule, bootstrapApplication } from '@an import Lara from '@primeng/themes/aura'; import { provideAnimationsAsync } from '@angular/platform-browser/animations/async'; import { providePrimeNG } from 'primeng/config'; -import { AppRoutingModule } from './app/app-routing.module'; -import { CarouselModule } from 'primeng/carousel'; -import { NgApexchartsModule } from 'ng-apexcharts'; -import { ToastModule } from 'primeng/toast'; -import { OrderListModule } from 'primeng/orderlist'; -import { ProgressSpinnerModule } from 'primeng/progressspinner'; -import { MatIconModule } from '@angular/material/icon'; -import { MatGridListModule } from '@angular/material/grid-list'; -import { ButtonModule } from 'primeng/button'; -import { MatToolbarModule } from '@angular/material/toolbar'; -import { MatButtonModule } from '@angular/material/button'; -import { MatInputModule } from '@angular/material/input'; -import { ReactiveFormsModule, FormsModule } from '@angular/forms'; -import { MatCardModule } from '@angular/material/card'; -import { MatDividerModule } from '@angular/material/divider'; -import { SidebarModule } from 'primeng/sidebar'; -import { MatSelectModule } from '@angular/material/select'; -import { MatFormFieldModule } from '@angular/material/form-field'; -import { SelectModule } from 'primeng/select'; -import { AccordionModule } from 'primeng/accordion'; -import { TableModule } from 'primeng/table'; -import { TreeModule } from 'primeng/tree'; -import { InputTextModule } from 'primeng/inputtext'; -import { InputNumberModule } from 'primeng/inputnumber'; -import { PasswordModule } from 'primeng/password'; +import { provideRouter } from '@angular/router'; +import { routes } from './app/app-routing.module'; import { importProvidersFrom, provideExperimentalZonelessChangeDetection } from '@angular/core'; import AppContextComponent from './app/context/app-context.component'; -import { ToggleSwitchModule } from 'primeng/toggleswitch'; bootstrapApplication(AppContextComponent, { providers: [ - importProvidersFrom( - BrowserModule, - AppRoutingModule, - CarouselModule, - NgApexchartsModule, - NgApexchartsModule, - ToastModule, - OrderListModule, - ProgressSpinnerModule, - MatIconModule, - MatGridListModule, - DynamicDialogModule, - ButtonModule, - MatToolbarModule, - MatButtonModule, - MatInputModule, - ReactiveFormsModule, - MatCardModule, - MatDividerModule, - SidebarModule, - MatSelectModule, - MatFormFieldModule, - FormsModule, - SelectModule, - AccordionModule, - TableModule, - TreeModule, - InputTextModule, - InputNumberModule, - PasswordModule, - ToggleSwitchModule - ), + provideRouter(routes), + importProvidersFrom(BrowserModule, DynamicDialogModule), DialogService, MessageService, ChipFaultPipe,