0

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
  • what Angular version are you using? Commented Dec 16, 2019 at 10:25
  • @Andrei: Angular 7.2 Commented Dec 16, 2019 at 10:37

2 Answers 2

1

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)
Sign up to request clarification or add additional context in comments.

4 Comments

it seem that PATH_TO_MODULE cannot be used with module loading through Http
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.
Thank, I understand your idea. But I need to explicit set PATH_TO_MODULE = 'example/module.js'
If I put chunked module js to different domaim can it be loaded as normally?
1
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

I need to load module from HTTP; using your way module will be built directly by Webpack not loading from HTTP
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)?
Yes, two modules are separately.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.