manfredsteyer / module-federation-with-angular-dynamic

Dynamic Module Federation with Angular
121 stars 67 forks source link

No AOT #7

Open stefanocke opened 3 years ago

stefanocke commented 3 years ago

When looking at the bundles loaded for the shell in the browser, I can see that angular/compiler is included.

The reason for that is, that platformBrowserDynamic() is used and has not been transformed to platformBrowser() by the Angular build.

I am not really sure, why this transformation is not applied. Some first debugging shows me, that "entryModule" seems to be always null here:

https://github.com/angular/angular-cli/blob/decb05b2fe5a19593188892e7edfc6f009019c5d/packages/ngtools/webpack/src/transformers/replace_bootstrap.ts#L29

@manfredsteyer , is this someting that is likely to be fixed with (better) WebPack 5 support in Anuglar 12? Or is this something that is special to the customized build that we have here?

P.S.: I use Windows.

stefanocke commented 3 years ago

I suspect it comes from the additional bootstrap.ts.

When the Angular Build is trying to determine the entry module, it seems to look for "bootstrapModule" or "bootstrapModuleFactory": https://github.com/angular/angular-cli/blob/decb05b2fe5a19593188892e7edfc6f009019c5d/packages/ngtools/webpack/src/entry_resolver.ts#L150

Since main.ts does not contain the one or the other, but only the import for bootstrap.ts, it is not considered as entryModule. So, entryModule stays null.

stefanocke commented 3 years ago

workaround / solution:

Configure entry module for shell explicitely in its tsconfig.json:

{
  "extends": "../../tsconfig.json",
  "compilerOptions": {
    "outDir": "../../out-tsc/app",
    "types": []
  },
  "files": [
    "src/main.ts",
    "src/polyfills.ts"
  ],
  "include": [
    "src/**/*.d.ts"
  ],
  "angularCompilerOptions": {
    "entryModule": "./src/app/app.module#AppModule"
  }

}

works for me.