Skip to content

feat(dts-plugin): support custom outputDir for DTS type emission#4487

Open
zhouxinyong wants to merge 4 commits intomodule-federation:mainfrom
zhouxinyong:feat/dts-custom-output-dir
Open

feat(dts-plugin): support custom outputDir for DTS type emission#4487
zhouxinyong wants to merge 4 commits intomodule-federation:mainfrom
zhouxinyong:feat/dts-custom-output-dir

Conversation

@zhouxinyong
Copy link

Description

When webpack entry files are output to a subdirectory (e.g. dist/react/production/), the DTS plugin always emits @mf-types.zip and @mf-types.d.ts to the compiler output root (dist/react/). Consumers infer the types URL from the entry path, resulting in 404s.

This PR makes two minimal changes:

  1. Expose outputDir in SDK typesDtsRemoteOptions now includes outputDir?: string, allowing users to configure where types are emitted.
  2. Fix asset emission pathGenerateTypesPlugin now uses path.relative() instead of path.basename() to compute asset names, so types land in the correct subdirectory relative to the compiler output.

Usage

new ModuleFederationPlugin({
  dts: {
    generateTypes: {
      outputDir: `dist/react/${process.env.DEPLOY_ENVIRONMENT || 'production'}`
    }
  }
})

Backward Compatibility

  • Default behavior is unchanged: when outputDir is not set, path.relative() produces the same result as the previous path.basename().
  • No breaking changes to existing APIs.

Related Issue

N/A (workaround previously required a post-build copy script)

Types of changes

  • Docs change / refactoring / dependency upgrade
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)

Checklist

  • I have added tests to cover my changes.
  • All new and existing tests passed.
  • I have updated the documentation.

Expose the existing internal `outputDir` option in the SDK's `DtsRemoteOptions`
interface and fix `GenerateTypesPlugin` to use `path.relative()` instead of
`path.basename()` when computing asset emission paths. This allows users to
configure a custom output directory so that `@mf-types.zip` and `@mf-types.d.ts`
are emitted alongside entry files in subdirectories (e.g. `dist/react/production/`).

Previously, even if `outputDir` was set internally, `emitAsset()` always stripped
directory info via `path.basename()`, causing the zip to land at the compiler
output root instead of the intended subdirectory.
@changeset-bot
Copy link

changeset-bot bot commented Mar 2, 2026

🦋 Changeset detected

Latest commit: c5d10e5

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 43 packages
Name Type
@module-federation/dts-plugin Major
@module-federation/sdk Major
@module-federation/cli Major
@module-federation/enhanced Major
@module-federation/manifest Major
@module-federation/metro Major
@module-federation/rspack Major
@module-federation/devtools Major
@module-federation/data-prefetch Major
@module-federation/esbuild Patch
@module-federation/managers Major
@module-federation/modern-js-v3 Major
@module-federation/modern-js Patch
@module-federation/nextjs-mf Patch
@module-federation/node Patch
@module-federation/retry-plugin Major
@module-federation/rsbuild-plugin Major
@module-federation/rspress-plugin Major
@module-federation/runtime-core Major
@module-federation/runtime Major
@module-federation/storybook-addon Major
@module-federation/utilities Patch
@module-federation/webpack-bundler-runtime Major
@module-federation/bridge-react-webpack-plugin Major
@module-federation/bridge-react Major
@module-federation/bridge-vue3 Major
shared-tree-shaking-no-server-host Patch
shared-tree-shaking-no-server-provider Patch
@module-federation/metro-plugin-rnc-cli Major
@module-federation/metro-plugin-rnef Major
shared-tree-shaking-with-server-host Patch
shared-tree-shaking-with-server-provider Patch
remote5 Patch
remote6 Patch
website-new Patch
@module-federation/runtime-tools Major
@module-federation/inject-external-runtime-core-plugin Major
@module-federation/third-party-dts-extractor Major
@module-federation/bridge-shared Major
@module-federation/error-codes Major
create-module-federation Major
@module-federation/treeshake-server Major
@module-federation/treeshake-frontend Major

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@netlify
Copy link

netlify bot commented Mar 2, 2026

Deploy Preview for module-federation-docs ready!

Name Link
🔨 Latest commit c5d10e5
🔍 Latest deploy log https://app.netlify.com/projects/module-federation-docs/deploys/69a61d4388c11600086a5ee5
😎 Deploy Preview https://deploy-preview-4487--module-federation-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: dc5e1f0faa

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@github-actions
Copy link
Contributor

github-actions bot commented Mar 2, 2026

Bundle Size Report

4 package(s) changed, 37 unchanged.

Package Total dist Delta ESM gzip Delta
dts-plugin 298.3 kB +1.8 kB (+0.6%) 4.5 kB +221 B (+5.0%)
sdk 108.3 kB +181 B (+0.2%) 755 B no change
runtime-tools 4.8 kB -39 B (-0.8%) 95 B no change
runtime 17.2 kB +13 B (+0.1%) 634 B no change

Total dist: 6.70 MB (+1.9 kB (+0.0%))
Total ESM gzip: 79.2 kB (+221 B (+0.3%))

@pkg-pr-new
Copy link

pkg-pr-new bot commented Mar 2, 2026

Open in StackBlitz

@module-federation/devtools

pnpm add https://pkg.pr.new/@module-federation/devtools@4487

@module-federation/cli

pnpm add https://pkg.pr.new/@module-federation/cli@4487

create-module-federation

pnpm add https://pkg.pr.new/create-module-federation@4487

@module-federation/data-prefetch

pnpm add https://pkg.pr.new/@module-federation/data-prefetch@4487

@module-federation/dts-plugin

pnpm add https://pkg.pr.new/@module-federation/dts-plugin@4487

@module-federation/enhanced

pnpm add https://pkg.pr.new/@module-federation/enhanced@4487

@module-federation/error-codes

pnpm add https://pkg.pr.new/@module-federation/error-codes@4487

@module-federation/esbuild

pnpm add https://pkg.pr.new/@module-federation/esbuild@4487

@module-federation/managers

pnpm add https://pkg.pr.new/@module-federation/managers@4487

@module-federation/manifest

pnpm add https://pkg.pr.new/@module-federation/manifest@4487

@module-federation/metro

pnpm add https://pkg.pr.new/@module-federation/metro@4487

@module-federation/metro-plugin-rnc-cli

pnpm add https://pkg.pr.new/@module-federation/metro-plugin-rnc-cli@4487

@module-federation/metro-plugin-rnef

pnpm add https://pkg.pr.new/@module-federation/metro-plugin-rnef@4487

@module-federation/modern-js

pnpm add https://pkg.pr.new/@module-federation/modern-js@4487

@module-federation/modern-js-v3

pnpm add https://pkg.pr.new/@module-federation/modern-js-v3@4487

@module-federation/native-federation-tests

pnpm add https://pkg.pr.new/@module-federation/native-federation-tests@4487

@module-federation/native-federation-typescript

pnpm add https://pkg.pr.new/@module-federation/native-federation-typescript@4487

@module-federation/nextjs-mf

pnpm add https://pkg.pr.new/@module-federation/nextjs-mf@4487

@module-federation/node

pnpm add https://pkg.pr.new/@module-federation/node@4487

@module-federation/retry-plugin

pnpm add https://pkg.pr.new/@module-federation/retry-plugin@4487

@module-federation/rsbuild-plugin

pnpm add https://pkg.pr.new/@module-federation/rsbuild-plugin@4487

@module-federation/rspack

pnpm add https://pkg.pr.new/@module-federation/rspack@4487

@module-federation/rspress-plugin

pnpm add https://pkg.pr.new/@module-federation/rspress-plugin@4487

@module-federation/runtime

pnpm add https://pkg.pr.new/@module-federation/runtime@4487

@module-federation/runtime-core

pnpm add https://pkg.pr.new/@module-federation/runtime-core@4487

@module-federation/runtime-tools

pnpm add https://pkg.pr.new/@module-federation/runtime-tools@4487

@module-federation/sdk

pnpm add https://pkg.pr.new/@module-federation/sdk@4487

@module-federation/storybook-addon

pnpm add https://pkg.pr.new/@module-federation/storybook-addon@4487

@module-federation/third-party-dts-extractor

pnpm add https://pkg.pr.new/@module-federation/third-party-dts-extractor@4487

@module-federation/treeshake-frontend

pnpm add https://pkg.pr.new/@module-federation/treeshake-frontend@4487

@module-federation/treeshake-server

pnpm add https://pkg.pr.new/@module-federation/treeshake-server@4487

@module-federation/typescript

pnpm add https://pkg.pr.new/@module-federation/typescript@4487

@module-federation/utilities

pnpm add https://pkg.pr.new/@module-federation/utilities@4487

@module-federation/webpack-bundler-runtime

pnpm add https://pkg.pr.new/@module-federation/webpack-bundler-runtime@4487

@module-federation/bridge-react

pnpm add https://pkg.pr.new/@module-federation/bridge-react@4487

@module-federation/bridge-react-webpack-plugin

pnpm add https://pkg.pr.new/@module-federation/bridge-react-webpack-plugin@4487

@module-federation/bridge-shared

pnpm add https://pkg.pr.new/@module-federation/bridge-shared@4487

@module-federation/bridge-vue3

pnpm add https://pkg.pr.new/@module-federation/bridge-vue3@4487

@module-federation/inject-external-runtime-core-plugin

pnpm add https://pkg.pr.new/@module-federation/inject-external-runtime-core-plugin@4487

commit: d84f793

@2heal1
Copy link
Member

2heal1 commented Mar 3, 2026

I can not reproduce it . Can you provide the minimal reproduce repo ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants