dkhrunov / ngx-mfe

Angular library for working with micro-frontends in Webpack 5 and plugin ModuleFederation
https://www.npmjs.com/package/ngx-mfe
MIT License
22 stars 4 forks source link

Provide a way to configure module in an async way #18

Closed out-dev closed 1 year ago

out-dev commented 1 year ago

First - Great job your lib simplifies so much.

Can you offer a way to configure the modul asynchronously.

You could inject the NgxMfeOptions in forRoot or offer another method forRootAsync(options$: Obeservable) | forRootAsync(options$: Promise)

So that the individual mfe configurations can also be obtained via api or fetch.

https://github.com/dkhrunov/ngx-mfe/blob/72b0ec65d761ce67908701cc303f906dc9d36424/projects/ngx-mfe/src/lib/mfe.module.ts#L25

dkhrunov commented 1 year ago

Can you load your config when app is starting?

For example:

@NgModule({
  imports: [BrowserModule, HttpClientModule],
  declarations: [AppComponent],
  bootstrap: [AppComponent],
  providers: [{
    provide: APP_INITIALIZER,
    useFactory: loadConfig,
    deps: [HttpClient],
    multi: true
  }]
})
export class AppModule {}
out-dev commented 1 year ago

Yes I can but if forRoot(xxx) is called the providers gets overriden right?

Or what is your idea?

Ps: Great response time ;-)

out-dev commented 1 year ago

Unfotunatly "@angular-architects/module-federation" does not provide already loaded MFE Manifest

dkhrunov commented 1 year ago

Yes I can but if forRoot(xxx) is called the providers gets overriden right?

yes

Or what is your idea?

I collect all requirements of your problem, and try to form a universal solution that would suit not only your case

dkhrunov commented 1 year ago

Can you give me more code with your sample ? Have you example repository?

dkhrunov commented 1 year ago

You want load MFE Manifest and provide it to forRoot({ mfeConfig: ##here## }) as Promise or Observable, right? Or you want load all config for configure lib forRoot(##all config as Promise or Observable##)?

out-dev commented 1 year ago

Currently my MFE configuration comes from an Api call. I would like to use the result for the following configuration NgxMfeOptions['mfeConfig'].

I can make the API call in the APP_INITIALIZER or in a factory but how can I use the result in forRoot or make it known to the MfeModule for configuration?

Or am I completely blind?

dkhrunov commented 1 year ago

Now i need time to figure out a solution, I m comeback when have solution.

Have you example repository?

Pigzields commented 1 year ago

Hi, currently I have implement microfrontends with @angular-architects/module-federation and using the manifest concept so basically using loadRemoteModule method in routing with type = 'manifest'

If I implement this library is it possible for ngx-mfe to read the manifest directly as anyhow loadManifest is called in the main.ts ?

dkhrunov commented 1 year ago

Hi, currently I have implement microfrontends with @angular-architects/module-federation and using the manifest concept so basically using loadRemoteModule method in routing with type = 'manifest'

If I implement this library is it possible for ngx-mfe to read the manifest directly as anyhow loadManifest is called in the main.ts ?

Hi, idk, I haven't worked with the mfe concept in production for a long time. Can you provide me with a code sample or repository, it's hard to answer a question without diving into the problem.

dkhrunov commented 1 year ago

@out-dev Hi, you can now try to load your config asynchronously [Pull request #19], like this:

MfeModule.forRoot({
  mfeConfig: {
    useLoader:  (http: HttpClient): Observable<MfeConfig> => http.get<MfeConfig>('/manifest.json'),
    deps: [HttpClient]
  },
})

Update lib to v15.1.0. Read more here

out-dev commented 1 year ago

Will try it out :-)