I have a problem regarding lighthouse issue on my angular app with lazy loading. Basically my app contains 3 big chunks of feature that should be lazy loaded. So when you open the feature A, I expect the app not to load the scripts for feature B and C at all, and vice versa.
But somehow, when I check with lighthouse, it reports back that I can "remove unused JavaScript" on the other JS files that contains the whole functionality of the other features. Even worse, one of the feature depends on ngx-quill for rich-text editor, and this also got loaded although I open a feature that does not need it.
Am I missing something here?
EDIT:
I have these following *-routing.modules.ts:
- app-routing
import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
const routes: Routes = [
{ path: '', loadChildren: () => import('./feature-a/feature-a.module').then(m => m.FeatureAModule) },
{ path: 'feature-b', loadChildren: () => import('./feature-b/feature-b.module').then(m => m.FeatureBModule) },
{ path: '**', redirectTo: '', pathMatch: 'full' }
];
@NgModule({
imports: [
RouterModule.forRoot(routes, { relativeLinkResolution: 'legacy' })
],
exports: [RouterModule]
})
export class AppRoutingModule { }
feature-a: nothing of interest, no lazy loading here.
feature-b:
import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { LandingPageComponent } from './pages/landing-page/landing-page';
import { FeatureBPage } from './feature-b.page';
const routes: Routes = [
{
path: '',
component: FeatureBPage,
children: [
{ path: '', redirectTo: 'home', pathMatch: 'full' },
{ path: 'home', component: LandingPageComponent },
{
path: 'feature-c',
loadChildren: () =>
import('./feature-c/feature-c.module').then(
(m) => m.FeatureCModule
),
},
{ path: '**', redirectTo: '', pathMatch: 'full' }
],
},
];
@NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule],
})
export class FeatureBRoutingModule {}
- feature-c: contains multiple other lazy loaded features (feature-c1, -c2, -c3, etc), but none of those are being referenced by Feature A and/or Feature B.