We are using tsup and esbuild together with Microbundle to build our component library.
Each component builds to its own dist directory with:
index.d.ts– TypeScript type declaration fileindex.js– CJS (CommonJS)index.modern.mjs– Modern output (work in all modern browsers)index.module.js– legacy ESM (ES Modules) output (for bundlers)index.umd.js– legacy UMD (Universal Module Definition) output (for Node & CDN use)
npm run-script buildWe emit CJS and ESM using a dual-package approach with tsc and tsconfig-to-dual-package for some packages.
This ensures Node/TypeScript point to the right package type (commonjs, module) depending on the consumer's configuration, without the hassle of us to "hack" the main package.json and tsconfig to satisfy all use cases.
The build has the following structure in its own dist directory:
./cjs– CJS (CommonJS) with declaration + inline source map../esm– ESM (ES Modules) with declaration + inline source map.