angular CLI (Webpack) lazy loading of dynamically created routes

Viewed 382

Simplified Scenario:

A. User Logs in

B. Server will authorise the user and also send back the accessible routes i.e. :

{
  new {
    itemID = 1,
      name = "Users",
      parent = "Administration",
      icon = "??",
      path = "user",
      loadChildren = "./adm-user/adm-user.module#AdmUserModule"
    //"../adm-user/adm-user.module#AdmUserModule"
  },
  new {
    itemID = 1,
      name = "Roles",
      parent = "Administration",
      icon = "??",

      path = "role",
      loadChildren = "../adm-user/adm-useaar.module#AdmRoleModule"
  }
}

C. My Angular code uses the returned values to manipulate the routerConfig and add the returned routes.

Issue: It looks like Angular CLI (WebPack) ng server and ng build module are not creating any bundles for the AdmUserModule and AdmRoleModule. I guess this is because there is no reference to these in the code and it's being created dynamically.

  • Note: when I hard code the routes and build I get more bundles created and everything works fine

Question: Is There anyway to force webpack/Angular CLI to create bundles even though it can't find references in the code? or is there a known solution for this issue?

Question (added): If There is no straight forward way can anyone explain to me how can I make webpack bundle individual angular modules? This way I can copy those bundles manually with the main framework bundles and hopefully achieve the same.

0 Answers
Related