Skip to content

Commit

Permalink
Merge pull request #36 from dhalbrook/main
Browse files Browse the repository at this point in the history
Add support for specifying the module federation plugin name
  • Loading branch information
steven-pribilinskiy authored Oct 17, 2023
2 parents c42e0b0 + 207344d commit 0c231b2
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ Requirements:
"name": "microapp-42",
"exposes": {
"./Button": "./src/view-layer/components/Button",
"./Portal": "./src/view-layer/index"
"./Portal": "./src/view-layer/index",
"./Http": "./src/wmf-expose/Http"
}
}
Expand Down Expand Up @@ -146,6 +146,7 @@ To enable verbose logging add folowing in webpack config:
| `remoteEntryUrls` | `RemoteEntryUrls` | `{}` | Base URLs for types. These should target compiled bundles that also contain the types. E.g. with `{ mfeApp: 'https://assets.mydomain.com/mfe-app' }` the types will be downloaded from `'https://assets.mydomain.com/mfe-app/@types/index.d.ts'`. More details available in [this section](#templated-remote-urls) |
| `remoteManifestUrls` | `RemoteManifestUrls` | `{}` | URLs to remote manifest files. A manifest contains a URL to a remote entry that is substituted in runtime. <br><br> More details available in [this section](#templated-remote-urls) |
| `cloudbedsRemoteManifestsBaseUrl` | `string` | `'/remotes/dev-ga'` | Base URL for remote `remote-entries.json` manifest file that is specific to Cloudbeds microapps <br><br> _Examples:_ <br> `http://localhost:4480/remotes/dev` (or `/dev-docker`) <br> `https://cb-front.cloudbeds-dev.com/remotes/[env]`. <br><br> `remoteManifestUrls` is ignored when this setting has a value other than `undefined`. |
| `mfPluginName` | `string` | `ModuleFederationPlugin` | The name of the module federation plugin. Change this to "NextFederationPlugin" if you are using this plugin with @module-federation/nextjs-mf |


## Consuming remote types
Expand Down
7 changes: 6 additions & 1 deletion src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import {
let isCompiledOnce = false;
let isDownloadedOnce = false;

const DEFAULT_MODULE_FEDERATION_PLUGIN_NAME = 'ModuleFederationPlugin';

export class ModuleFederationTypesPlugin implements WebpackPluginInstance {
constructor(public options?: ModuleFederationTypesPluginOptions) {}

Expand Down Expand Up @@ -55,9 +57,12 @@ export class ModuleFederationTypesPlugin implements WebpackPluginInstance {
return;
}

// Allow for other module federation plugins such as this "NextFederationPlugin"
const mfPluginName = this.options?.mfPluginName ?? DEFAULT_MODULE_FEDERATION_PLUGIN_NAME;

// Get ModuleFederationPlugin config
const federationOptions = compiler.options.plugins.find((plugin) => {
return plugin!.constructor.name === 'ModuleFederationPlugin';
return plugin!.constructor.name === mfPluginName;
});
const federationPluginOptions: ModuleFederationPluginOptions = (federationOptions as any)?._options;
if (!federationPluginOptions?.name) {
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export type ModuleFederationTypesPluginOptions = {
remoteEntryUrls?: RemoteEntryUrls,
remoteManifestUrls?: RemoteManifestUrls,
remoteManifestUrl?: string,
mfPluginName?: string

cloudbedsRemoteManifestsBaseUrl?: string | ''
| 'dev' | 'dev-ga'
Expand Down

0 comments on commit 0c231b2

Please sign in to comment.