I'm trying to split Angular 7.2 app into app and two module; each will be build with Webpack. Main app will load module 1, module 2 from HTTP as children in app.routing.ts Is there anyway to do that?
2 Answers
I know it might not be the answer you've been looking for since you've mentioned v7. And still...
If you only update to V8 (And migrating from 7 to 8 should be really easy update) you can use the simple es import function to load any module even using the router, but also without him.
import(PATH_TO_MODULE).then(m => m.MODULE_NAME)
4 Comments
o0omycomputero0o
it seem that PATH_TO_MODULE cannot be used with module loading through Http
Eliran Eliassy
It will use webpack to create a chunked js from your module. When you will call the import statement it will get the chunk using http.
o0omycomputero0o
Thank, I understand your idea. But I need to explicit set PATH_TO_MODULE = 'example/module.js'
o0omycomputero0o
If I put chunked module js to different domaim can it be loaded as normally?
RouterModule.forRoot([
...
{path: 'path1', loadChildren: './module1/module1.module#Module1Module'},
{path: 'path2', loadChildren: './module2/module2.module#Module2Module'}
])
with this way angular will detect lazy modules, build them separately and force them to load when appropriate path is in the url
3 Comments
o0omycomputero0o
I need to load module from HTTP; using your way module will be built directly by Webpack not loading from HTTP
Andrei
it will be build by webpack and loaded by http. Am I right that you want to build modules separately (different git repositories for example)?
o0omycomputero0o
Yes, two modules are separately.