Migrate bundling to rolldown-based setup
At the moment, Primer React is bundled via rollup. To improve build speed, switching to Rolldown, either plain or via a bundler like tsdown or obuild might be worth a shot.
Hi there, @TheAlexLichter! 👋 Thanks for reaching out about this!
I actually tried out rolldown recently to see if it worked in our existing setup (specifically with rolldown -c rollup.config.mjs in packages/react but sadly ran into some errors with @rollup/plugin-commonjs and then our custom 'preserve-directives' plugin for making sure that client directives (like 'use client') appear in specific bundles we ship.
Curious if you have any thoughts on how to fix these or if there was anything you'd recommend doing 👀
Hey @joshblack 👋
-
@rollup/plugin-commonjsshould be supported out of the box, so you could try removing it in the config. Which issues did you encounter? - Same for the custom rollup plugin - any issue you've seen.
Sure thing @TheAlexLichter, I opened up a PR here to make it easier to share/talk about: https://github.com/primer/react/pull/6175
I removed the commonjs plugin and then got this error:
[plugin preserve-directives]
RangeError: Maximum call stack size exceeded
at get preserveModules (file:///Users/joshblack/gh/primer/react/node_modules/rolldown/dist/shared/src-IinHd_xa.mjs:3267:16)
at get preserveModules (file:///Users/joshblack/gh/primer/react/node_modules/rolldown/dist/shared/src-IinHd_xa.mjs:3267:16)
at get preserveModules (file:///Users/joshblack/gh/primer/react/node_modules/rolldown/dist/shared/src-IinHd_xa.mjs:3267:16)
at get preserveModules (file:///Users/joshblack/gh/primer/react/node_modules/rolldown/dist/shared/src-IinHd_xa.mjs:3267:16)
at get preserveModules (file:///Users/joshblack/gh/primer/react/node_modules/rolldown/dist/shared/src-IinHd_xa.mjs:3267:16)
at get preserveModules (file:///Users/joshblack/gh/primer/react/node_modules/rolldown/dist/shared/src-IinHd_xa.mjs:3267:16)
at get preserveModules (file:///Users/joshblack/gh/primer/react/node_modules/rolldown/dist/shared/src-IinHd_xa.mjs:3267:16)
[TRUNCATED]
I believe this is coming from this line but let me know if I'm misunderstanding 👀
If I remove that option lookup, I also start seeing some missing export warnings like:
[MISSING_EXPORT] Warning: "ActionMenu" is not exported by "src/ActionMenu/index.ts".
╭─[ src/index.ts:34:10 ]
│
34 │ export { ActionMenu } from './ActionMenu';
│ ─────┬────
│ ╰────── Missing export
────╯
I believe these exports should exist, the common pattern that seemed to come up is that these were using wildcard exports (e.g. export * from 'mod') so that might have something to do with it.