4

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.

Asha
  • 3,871
  • 7
  • 44
  • 57
  • Have you found something? We're doing the same – Lev Jul 28 '17 at 09:50
  • No, Have tried everywhere! nobody seems to be having an answer! – Asha Jul 28 '17 at 11:09
  • Hey, I 'm trying something similar, but haven't found a solution yet. Please see my question; https://stackoverflow.com/questions/50149016/load-new-modules-dynamically-in-run-time-with-angular-cli-angular-5 – Lars Meijdam May 03 '18 at 07:17
  • I created a repository on github with a solution which might help. It uses Angular 6 libraries and 1 base applications which load up the UMD bundled libraries lazily; https://github.com/lmeijdam/angular-umd-dynamic-example If you have any suggestions, please feel free to add! – Lars Meijdam May 09 '18 at 06:37
  • any success with this problem. Looking for similar solution. LAzy loaded modules are not compiling and hence not available in case of dynamic routing. Also can you share the code you used for creating routes dynamically. I am using AppInitializer for same, wondering if any other better solution. – Sukesh Marla Jul 06 '18 at 07:56
  • @SukeshMarla After struggling for a long time and not finding a solution I decided to move on and try other frameworks. I have implemented the same idea in React 16.x now (using Create-React-App) and it's working fine. Please note I'm not saying one framework is better than the other or Angular can't do this! just that I found my solution in moving from Angular to React! – Asha Jul 12 '18 at 10:28

0 Answers0