Skip to content

Lazy loading and webpack bundling Incompatibility #1200

Closed

Description

@bzaruk

Hi :)

I lately refactor my project to work with lazy loaded module and webpack bundling for better performance.
so first of all this is crazy how fast my app become on bootstrap! :)

but the only thing that is kind of frustrating is that when I define a routes for for lazy loaded module that contains a children is it kind of tricky, because the way that I need to define the children when I only use it for debugging (without bundling) is different from the way I need to define it with bundling, and I will give an example:

without bundling - the relative path for the children module is relative to the app folder:

export const routes = [
    {
        path: '',
        component: ParentComponent,
        children: [
            {
                path: 'secondChilldren',
                loadChildren: "./pages/secondChilldren/secondChilldren/secondChilldren.module#SecondChilldrenModule",
            },
            {
                path: 'firstChildren',
                loadChildren: "./pages/firstChildren/firstChildren/firstChildren.module#FirstChildrenModule",
            },
            { path: '', redirectTo: 'firstChildren', pathMatch: 'full' },
        ]
    }
];

With bundling - the relative path for the children module is relative to the parentComponent folder:

export const routes = [
    {
        path: '',
        component: ParentComponent,
        children: [
            {
                path: 'secondChilldren',
                loadChildren: "../secondChilldren/secondChilldren/secondChilldren.module#SecondChilldrenModule",
            },
            {
                path: 'firstChildren',
                loadChildren: "../firstChildren/firstChildren/firstChildren.module#FirstChildrenModule",
            },
            { path: '', redirectTo: 'firstChildren', pathMatch: 'full' },
        ]
    }
];

little update:
The issue is all about the relative path of nested lazy loading component, cause I checked it and when set the route of the children not to be lazy loaded and set it with the actual component ( like this: component: firstChildrenComponent instead of loadChildren: "../firstChildren/firstChildren/firstChildren.module#FirstChildrenModule" ), it works.
but still it would be great to figure it out how to do it with nested lazy loading. :)

Thank you! :)

Activity

  1. NickIliev commented on Feb 13, 2018

    @NickIliev

    @shabib3 glad to hear you have achieved such great performance boost!

    Regarding your issue with the relative and absolute paths of the lazily loaded modules (with or without Webpack) - I can confirm that this is indeed a real issue logged here.
    We are currently working on it and will post any additional info in the linked issue - meanwhile continue using the workaround you have found.

  2. bzaruk commented on Feb 13, 2018

    @bzaruk
    Author

    @NickIliev

    Just to add another thing - my little update that I wrote not really works for both situation (regular and bundling)...it iד actually the same situation that works only for bundling.

    so for this situation, the workaround is to change the relative path when running with bundling :)

  3. FrontEnd-Miracle-1 commented on Aug 19, 2018

    @FrontEnd-Miracle-1

    @shabib3 - When you say "so for this situation, the workaround is to change the relative path when running with bundling", do you mean that you simply don't use Lazy Loading together with Webpack in your project?

    I am asking because I have the apparently unanswerable error "No module factory available for dependency type: ContextElementDependency at Compilation". And it is caused by the "loadChildren" with the relative path of nested lazy loading...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions