Skip to content

Commit

Permalink
feat: support Rspack ModuleFederationPluginV1
Browse files Browse the repository at this point in the history
  • Loading branch information
steven-pribilinskiy committed Feb 4, 2024
1 parent d982b65 commit b02b9c5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
File renamed without changes.
14 changes: 7 additions & 7 deletions src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ import {
let isCompiledOnce = false;
const isDownloadedOnce = false;

const DEFAULT_MODULE_FEDERATION_PLUGIN_NAME = 'ModuleFederationPlugin';

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

Expand Down Expand Up @@ -64,21 +62,23 @@ export class ModuleFederationTypesPlugin implements WebpackPluginInstance {
return;
}

// Allow for other module federation plugins such as this "NextFederationPlugin"
const moduleFederationPluginName = this.options?.moduleFederationPluginName
?? DEFAULT_MODULE_FEDERATION_PLUGIN_NAME;
const moduleFederationPluginNames = [
this.options?.moduleFederationPluginName, // Custom module federation plugin, such as NextFederationPlugin
'ModuleFederationPlugin',
'ModuleFederationPluginV1', // WMF v1.0 in Rspack
];

// Get ModuleFederationPlugin config
const federationOptions = compiler.options.plugins.find(
plugin => plugin!.constructor.name === moduleFederationPluginName,
plugin => plugin!.constructor.name && moduleFederationPluginNames.includes(plugin!.constructor.name),
);

// eslint-disable-next-line no-underscore-dangle
const federationPluginOptions: ModuleFederationPluginOptions = (federationOptions as any)?._options;

if (!federationPluginOptions?.name) {
logger.warn(
`Plugin disabled as ${moduleFederationPluginName} is not configured properly. The 'name' option is missing.`,
'Plugin disabled as ModuleFederationPlugin is not configured properly. The "name" option is missing.',
);
return;
}
Expand Down

0 comments on commit b02b9c5

Please sign in to comment.