Newsletter
Join the Community
Subscribe to our newsletter for the latest news and updates
A tutorial repo with 7 setups for building shareable React component libraries, from bare to Tailwind and MUI.
Component Library Library is a GitHub tutorial repository that presents seven progressive setups for building shareable React component libraries, each with a library and a consuming Next.js app, using TypeScript, ES Modules, and tsup.
Component Library Library (CLL) is a pnpm-workspace monorepo where each of its seven levels demonstrates a different approach to sharing React components across repositories. The lowest level uses React's createElement with no build step, while later levels add TypeScript, ESLint, tsup, GitHub Actions, vanilla CSS, Tailwind CSS, Material UI theming, and SVG-to-React icon generation. Every library is built as an ES Module, is not minified, does not bundle its dependencies, and targets ESNext so the consuming application's bundler handles polyfills and minification.
createElement library (bare) and advancing through bare-ts, bare-ts-tooling, css, tailwind, mui, and icons.tsconfig.json with jsx: react-jsx, moduleResolution: nodenext, and declaration file output via tsup.dts: true, sourcemap: true, minify: false, and format: 'esm', reducing a sample compile from 2.4s to 1.4s.eslint-config-standard-with-typescript, eslint-plugin-react, and Prettier integration, with react/prop-types disabled in favor of TypeScript types.pnpm install, pnpm lint, and pnpm build on every push using Node 18 and pnpm 8.1.0.@apply, exposes a tailwindConfig preset, and disables Tailwind's preflight to avoid resets.createTheme theme for downstream apps.forwardRef, bundled by tsup.bare-ts-tooling level as a starting point and run pnpm build to get dist/index.js and dist/index.d.ts for publishing.tailwind level to expose tailwindConfig as an import so consuming Next.js apps match the library's theme.icons level: drop SVGs into src/icons, run pnpm build, and receive generated TSX components bundled as an ES module.mui level to export a theme created with createTheme, then extend it in applications using createTheme(theme, overrides).Yes, the repository uses pnpm with a workspace setup, but the author notes that everything works with npm or yarn. You can clone the repo, run pnpm install at the root, then pnpm build inside a library and pnpm dev in its Next.js app.
No. The libraries are not minified and do not bundle their dependencies. The consuming application's build step is responsible for minification, dependency resolution, and polyfilling, which is why the libraries compile to ESNext.
Level 4 uses vanilla CSS imported from styles.css. Level 5 shows Tailwind CSS with inline classes, @apply in component stylesheets, and a split Tailwind config. Level 6 uses Material UI theming. All CSS setups produce a dist/index.css that consumers import via an exports field.
Clone the repository, run pnpm install at the root, run pnpm build in the library directory of your choice, and run pnpm dev in its consuming application. The repo's GitHub Actions workflow runs the same lint and build steps on every push.
Level 3 includes a dev script that runs tsup --watch, which rebuilds the library automatically on file changes, and the same pattern can be applied to the other levels.
