I am working with a (.NET Framework MVC) web project that cannot be fully transferred to a full angular project, so I cannot use angular's routing to lazy load, but I also don't want to load everything where the angular components are used. It is an enterprise solution where it is not easy (and cheap) to say: "Hey, lets fully utilize angular and forget about the old project!".
So I have solved this, in my opinion, in a clean way to load different modules based on URL, to avoid loading everything all together:
main.ts
console.log("bootstrapping start");
if (window.location.pathname.toLowerCase().includes("contactplans/details")) {
console.log("bootstrapping contactplan details");
platformBrowserDynamic().bootstrapModule(ContactplanDetailsModule)
.catch(err => console.log(err));
} else if (window.location.pathname.toLowerCase().includes("contactplans/index") || window.location.pathname.toLowerCase().endsWith("contactplans") || window.location.pathname.toLowerCase().includes("settings/contactplans")) {
console.log("bootstrapping contactplan index");
platformBrowserDynamic().bootstrapModule(ContactplanListModule) //contact plan index and settings page
.catch(err => console.log(err));
}
console.log("bootstrap decision done, bootstrapping menu");
platformBrowserDynamic().bootstrapModule(MenuModule)
.catch(err => console.log(err));
So based on the URL, it loads modules and on every page it loads the menu module.
For the time being, I kind-of have to do it this way, this is just a small example the the usage of angular will grow significantly on more and more individual pages until we can more easily 'switch' to a full angular project (within .NET Core which works awesome together).
So, this works fine on development. Using ng build --watch does the desired things.
Now going production, running ng build --prod it creates issues. To me it looks more like a bug then something else.
In the below screenshot I demonstrate what is being produced after ng build --prod when I make modifications to above code.
So as you can see, when only using one line of bootstrap, it works fine, no errors.
But when I have multiple like I want to have, it changes the actual Module to function() {} which then gives the console error:
Uncaught Error: No NgModule metadata found for 'function(){}'.
Is this really a bug or am I doing something wrong?
