From 51dd83f7a796da304bd881e0bf1f7bd659440b5d Mon Sep 17 00:00:00 2001 From: Steven Prybylynskyi Date: Tue, 17 Oct 2023 09:48:48 +0200 Subject: [PATCH] feat: custom module federation plugin name --- README.md | 24 ++++++++++++------------ src/plugin.ts | 8 +++++--- src/types.ts | 2 +- 3 files changed, 18 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index dda9c4f..cea8850 100644 --- a/README.md +++ b/README.md @@ -135,18 +135,18 @@ To enable verbose logging add folowing in webpack config: ### Plugin Options -| Setting | Value | Default | Description | -|-----------------------------------------:|:--------------------:|:--------------------:|:-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| `dirEmittedTypes` | `string` | `@types` | Path to the output folder for emitted types, relative to the distribution folder | -| `dirGlobalTypes` | `string` | `src/@types` | Path to project's global ambient type definitions, relative to the working dir | -| `dirDownloadedTypes` | `string` | `src/@types/remotes` | Path to the output folder for downloaded types | -| `disableTypeCompilation` | `boolean` | `false` | Disable compilation of types | -| `disableDownladingRemoteTypes` | `boolean` | `false` | Disable downloading of remote types | -| `downloadTypesWhenIdleIntervalInSeconds` | `number`, `-1` | `60` | Synchronize types continusouly - compile types after every compilation, download when idle with a specified delay value in seconds.

`-1` - disables continuous synchronization (compile and download will happen only on startup). | -| `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.

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

_Examples:_
`http://localhost:4480/remotes/dev` (or `/dev-docker`)
`https://cb-front.cloudbeds-dev.com/remotes/[env]`.

`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 | +| Setting | Value | Default | Description | +|-----------------------------------------:|:--------------------:|:------------------------:|:-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| `dirEmittedTypes` | `string` | `@types` | Path to the output folder for emitted types, relative to the distribution folder | +| `dirGlobalTypes` | `string` | `src/@types` | Path to project's global ambient type definitions, relative to the working dir | +| `dirDownloadedTypes` | `string` | `src/@types/remotes` | Path to the output folder for downloaded types | +| `disableTypeCompilation` | `boolean` | `false` | Disable compilation of types | +| `disableDownladingRemoteTypes` | `boolean` | `false` | Disable downloading of remote types | +| `downloadTypesWhenIdleIntervalInSeconds` | `number`, `-1` | `60` | Synchronize types continusouly - compile types after every compilation, download when idle with a specified delay value in seconds.

`-1` - disables continuous synchronization (compile and download will happen only on startup). | +| `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.

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

_Examples:_
`http://localhost:4480/remotes/dev` (or `/dev-docker`)
`https://cb-front.cloudbeds-dev.com/remotes/[env]`.

`remoteManifestUrls` is ignored when this setting has a value other than `undefined`. | +| `moduleFederationPluginName` | `string` | `ModuleFederationPlugin` | The name of the Module Federation plugin. Change this to `NextFederationPlugin` if you are using this plugin with [@module-federation/nextjs-mf](https://www.npmjs.com/package/@module-federation/nextjs-mf) | ## Consuming remote types diff --git a/src/plugin.ts b/src/plugin.ts index b3f6999..c7c8fdf 100644 --- a/src/plugin.ts +++ b/src/plugin.ts @@ -58,15 +58,17 @@ export class ModuleFederationTypesPlugin implements WebpackPluginInstance { } // Allow for other module federation plugins such as this "NextFederationPlugin" - const mfPluginName = this.options?.mfPluginName ?? DEFAULT_MODULE_FEDERATION_PLUGIN_NAME; + const moduleFederationPluginName = this.options?.moduleFederationPluginName ?? DEFAULT_MODULE_FEDERATION_PLUGIN_NAME; // Get ModuleFederationPlugin config const federationOptions = compiler.options.plugins.find((plugin) => { - return plugin!.constructor.name === mfPluginName; + return plugin!.constructor.name === moduleFederationPluginName; }); const federationPluginOptions: ModuleFederationPluginOptions = (federationOptions as any)?._options; if (!federationPluginOptions?.name) { - logger.log('Plugin disabled as ModuleFederationPlugin is not configured properly. The `name` option is missing.'); + logger.warn( + `Plugin disabled as ${moduleFederationPluginName} is not configured properly. The 'name' option is missing.`, + ); return; } diff --git a/src/types.ts b/src/types.ts index 02bc3ae..b696828 100644 --- a/src/types.ts +++ b/src/types.ts @@ -34,10 +34,10 @@ export type ModuleFederationTypesPluginOptions = { disableDownladingRemoteTypes?: boolean, disableTypeCompilation?: boolean, downloadTypesWhenIdleIntervalInSeconds?: number, + moduleFederationPluginName?: string remoteEntryUrls?: RemoteEntryUrls, remoteManifestUrls?: RemoteManifestUrls, remoteManifestUrl?: string, - mfPluginName?: string cloudbedsRemoteManifestsBaseUrl?: string | '' | 'dev' | 'dev-ga'