Skip to content

Conversation

@Timeless0911
Copy link
Contributor

@Timeless0911 Timeless0911 commented Nov 25, 2025

Summary

  • Api extractor can not bundle @types/react.
image
  • A typical React component library often does not declare @types/react in peerDependencies but only in devDependencies. Following the autoExternal logic for dependency handling, Rslib will attempt to bundle @types/react into the declaration output files during the build. However, in practice, a component library should not bundle @types/react.

In this PR, default exclude @types/react from dts bundle.

Related Links

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).

Copilot AI review requested due to automatic review settings November 25, 2025 10:08
@netlify
Copy link

netlify bot commented Nov 25, 2025

Deploy Preview for rslib ready!

Name Link
🔨 Latest commit 24e9fba
🔍 Latest deploy log https://app.netlify.com/projects/rslib/deploys/6925803a8b28d10008d8e1f5
😎 Deploy Preview https://deploy-preview-1365--rslib.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.

Copilot finished reviewing on behalf of Timeless0911 November 25, 2025 10:12
@netlify
Copy link

netlify bot commented Nov 25, 2025

Deploy Preview for rslib ready!

Name Link
🔨 Latest commit 3503398
🔍 Latest deploy log https://app.netlify.com/projects/rslib/deploys/692580742ca14d000899a962
😎 Deploy Preview https://deploy-preview-1365--rslib.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
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR implements automatic exclusion of @types/react from declaration file bundles. Previously, when a React component library had @types/react in devDependencies but not in peerDependencies, Rslib would bundle it into the declaration output files according to the autoExternal logic. This PR fixes that behavior by introducing a default exclusion list.

Key Changes:

  • Added DEFAULT_EXCLUDED_PACKAGES constant containing @types/react to automatically exclude it from dts bundles
  • Updated documentation to reflect the change and generalize examples from @types/react to @types/foo
  • Modified react-component-bundle example to enable dts.bundle to demonstrate the feature

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

Show a summary per file
File Description
packages/plugin-dts/src/dts.ts Introduces DEFAULT_EXCLUDED_PACKAGES constant and filters bundled packages to exclude default packages
packages/plugin-dts/tests/external.test.ts Updates test setup to include default excluded packages in mock data for all tests
website/docs/en/guide/faq/features.mdx Corrects documentation links from #outputtarget to #outputexternals and updates example from @types/react to @types/foo
website/docs/zh/guide/faq/features.mdx Chinese translation of the same documentation updates
examples/react-component-bundle/rslib.config.ts Enables dts.bundle and comments out CJS format to demonstrate the feature

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@Timeless0911 Timeless0911 enabled auto-merge (squash) November 25, 2025 10:55
Copy link
Member

@fi3ework fi3ework left a comment

Choose a reason for hiding this comment

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

in terms of the best practice, do we need to add @types/react to peer deps in our template?

@Timeless0911
Copy link
Contributor Author

in terms of the best practice, do we need to add @types/react to peer deps in our template?

In fact, almost all tool templates don't include @types/react and @types/react-dom in the peer deps. This is likely because React versions within the monorepo projects in community are usually quite consistent, avoiding the type conflicts caused by pnpm's hoisting behavior.

I prefer to temporarily not add them to peer deps in the templates, and we just handle @types/react to prevent it from being bundled, especially since api-extractor can not bundle @types/react though.

@Timeless0911 Timeless0911 merged commit c18a3be into main Nov 25, 2025
17 checks passed
@Timeless0911 Timeless0911 deleted the exclude-types-react branch November 25, 2025 11:26
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