How to lazy load with chunks
See original GitHub issueHello,
I’ve been using ui-router since AngularJS, but I’ve never really felt the need to lazy-load modules until now, as performance is a major point for a project I’m working on. I’ve come into contact with the lazy-load mechanism of the default Angular Router before, but generally don’t like the default router, so I’d prefer to stay with ui-router.
My problem is that with the ui-router lazy loading, Angular doesn’t seem to generate separate chunks for lazy loaded modules, resulting in no size difference of the initial chunk. I’ve been following the guide for Angular (https://ui-router.github.io/guide/lazyloading#angular) and adjusted my code accordingly (see example module below).
media-player.module.ts
...
@NgModule({
declarations: [...],
imports: [
SharedModule,
UIRouterModule.forChild({
states: [{
name: 'mediaPlayer',
url: '/player/:id',
component: MediaPlayerComponent,
}],
}),
];
})
export class MediaPlayerModule { }
app.module.ts
...
@NgModule({
declarations: [...],
imports: [
UIRouterModule.forRoot({
states: [
...,
{
name: 'mediaPlayer.**',
loadChildren: async () => import('./modules/media-player/media-player.module').then((m) => m.MediaPlayerModule),
},
...,
],
initial: ...,
otherwise: ...,
config: ...,
}),
],
providers: [...],
bootstrap: [AppComponent],
})
export class AppModule {}
Issue Analytics
- State:
- Created 2 years ago
- Comments:11
Top Results From Across the Web
Webpack lazy-loading chunks - CodeX Team
Webpack supports splitting files to separate modules out of a box. This note will show you how to start using Webpack chunks and...
Read more >Lazy Loading | webpack
Lazy, or "on demand", loading is a great way to optimize your site or application. This practice essentially involves splitting your code at...
Read more >Lazy loading in Webpack | Uploadcare Blog
Learn about Lazy Loading in Webpack with Igor Adamenko! ... Entry chunks contain modules we set as entry points in webpack configuration.
Read more >Common Chunk and Lazy Loading in Angular - | juri.dev
The easiest way of applying lazy loading is to use the Angular Router's built-in functionality. const routes: Routes = [ { path: ' ......
Read more >A Guide to React Lazy Loading - In Plain English
By default, code split chunks are named by the index in which they are created. In the above example, LazyLoad is contained within...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Okay will do that, thank you very much for your help. Hope you have a pleasant Tuesday 😃
As the module holds the state definitions, I think that is normal. You can however (and I would encourage you to) split the lazyloaded routes each into a future state to minimize the chunk size and give the future state a full url description. that way the url is always known, even when the state itselt if not.