Skip to content

Commit

Permalink
feat: custom module federation plugin name
Browse files Browse the repository at this point in the history
  • Loading branch information
steven-pribilinskiy committed Oct 17, 2023
1 parent 0c231b2 commit 51dd83f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 16 deletions.
24 changes: 12 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. <br><br> `-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. <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 |
| 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. <br><br> `-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. <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`. |
| `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
Expand Down
8 changes: 5 additions & 3 deletions src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down

0 comments on commit 51dd83f

Please sign in to comment.