build(core): ship per-module dist so optimizePackageImports works (bunchee → tsdown) - #216
Merged
Conversation
…nchee → tsdown) Barrel-file optimizers (Next.js optimizePackageImports, bundler dev servers) can only unroll an import when the entry re-exports from real per-module files. The previous dist inlined all 120+ hooks into one bundle, so a Next.js dev page importing just useDebounce pulled in every hook (552 kB client chunk). bunchee cannot emit unbundled output and OOMs when given per-hook entry points. Switch the core build to tsdown with unbundle (preserveModules): dist now ships one file per module with a thin barrel entry. The same page now loads only useDebounce and its dependency chain (64 kB, −88%). - exports: require now maps to ./dist/index.js / ./dist/index.d.ts (tsdown CJS naming); ./useQRCode moves to ./dist/useQRCode/index.*; new "./*" wildcard enables direct subpath imports for any hook - root package.json: drop the now-unused bunchee dependency Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
childrentime
added a commit
that referenced
this pull request
Aug 6, 2026
Why index.ts re-exports hurt tree shaking, Next.js dev memory, and tsc, and how they breed circular dependencies — built on the real #216 bunchee→tsdown per-module dist migration (552 kB → 64 kB). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Replace bunchee with tsdown (
unbundle: true, i.e. preserveModules) for@reactuses/core, so dist ships one file per module with the entry as a thin barrel of re-exports instead of a single 172 kB bundle:tsdown.config.ts: esm + cjs, dts, unbundle, es2015 targetpackage.jsonexports:requirenow maps to./dist/index.js/./dist/index.d.ts(tsdown's CJS naming);./useQRCodemoves to./dist/useQRCode/index.*; new./*wildcard enables direct subpath imports (@reactuses/core/useDebounce) for any hookpackage.json: drop the now-unused bunchee dependencyWhy
Barrel-file optimizers (Next.js
optimizePackageImports, and bundler dev servers generally) can only "unroll" an import when the entry file re-exports from real per-module files. Our previous dist inlined all 120+ hooks into one bundle, so a Next.js (Turbopack) dev page importing justuseDebouncepulled in every hook: a 552 kB client chunk. bunchee cannot emit unbundled output (and OOMs when given 112 entry points).With this change the same page loads only
useDebounceand its real dependency chain: 64 kB (−88%).Test plan
pnpm --filter @reactuses/core test— 61 suites / 318 tests passpnpm --filter @reactuses/core run typecheck+pnpm lintpassoptimizePackageImports: ['@reactuses/core']: unused hooks no longer loaded (552 kB → 64 kB chunk)next build(prod) passesrequire/ ESMimport, main entry + subpath, both resolvetsc --noEmitunder bothbundlerandnodenextresolution passesuseQRCodestill externalizes the optionalqrcodepeer dep🤖 Generated with Claude Code