Skip to content

fix(dts-plugin): add dynamic-remote-type-hints-plugin to runtimePlugins if not disable #3758

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/quiet-bottles-unite.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@module-federation/dts-plugin': patch
'@module-federation/enhanced': patch
'@module-federation/rspack': patch
---

fix(dts-plugin): add dynamic-remote-type-hints-plugin to runtimePlugins if not disable
22 changes: 18 additions & 4 deletions packages/dts-plugin/src/plugins/DtsPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ export const normalizeDtsOptions = (

export class DtsPlugin implements WebpackPluginInstance {
options: moduleFederationPlugin.ModuleFederationPluginOptions;
clonedOptions: moduleFederationPlugin.ModuleFederationPluginOptions;
constructor(options: moduleFederationPlugin.ModuleFederationPluginOptions) {
this.options = options;
// Create a shallow clone of the options object to avoid mutating the original
this.clonedOptions = { ...options };
}

apply(compiler: Compiler) {
const { options } = this;

// Create a shallow clone of the options object to avoid mutating the original
const clonedOptions = { ...options };
const { options, clonedOptions } = this;

// Clean up query parameters in exposes paths without mutating original
if (options.exposes && typeof options.exposes === 'object') {
Expand Down Expand Up @@ -106,4 +106,18 @@ export class DtsPlugin implements WebpackPluginInstance {
fetchRemoteTypeUrlsResolve,
).apply(compiler);
}

addRuntimePlugins() {
const { options, clonedOptions } = this;
if (!clonedOptions.runtimePlugins) {
return;
}
if (!options.runtimePlugins) {
options.runtimePlugins = [];
}
clonedOptions.runtimePlugins.forEach((plugin) => {
options.runtimePlugins.includes(plugin) ||
options.runtimePlugins.push(plugin);
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,9 @@ class ModuleFederationPlugin implements WebpackPluginInstance {
}

if (options.dts !== false) {
new DtsPlugin(options).apply(compiler);
const dtsPlugin = new DtsPlugin(options);
dtsPlugin.apply(compiler);
dtsPlugin.addRuntimePlugins();
}
if (options.dataPrefetch) {
new PrefetchPlugin(options).apply(compiler);
Expand Down
4 changes: 3 additions & 1 deletion packages/rspack/src/ModuleFederationPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,10 @@ export class ModuleFederationPlugin implements RspackPluginInstance {
let disableDts = options.dts === false;

if (!disableDts) {
const dtsPlugin = new DtsPlugin(options);
// @ts-ignore
new DtsPlugin(options).apply(compiler);
dtsPlugin.apply(compiler);
dtsPlugin.addRuntimePlugins();
}
if (!disableManifest && options.exposes) {
try {
Expand Down