🌐
DEV Community
dev.to β€Ί alexeagleson β€Ί how-to-create-and-publish-a-react-component-library-2oe
How to Create and Publish a React Component Library - DEV Community
December 5, 2022 - This first configuration defines how the actual Javascript code of our library is generated. The second configuration object defines how our libraries types are distributed and uses the dts plugin to do so. The final step before we can run our first rollup is to define the values of "main" and "module" in our package.json file: ... { "name": "template-react-component-library", "version": "0.0.1", "description": "A simple template for a custom React component library", "scripts": { "rollup": "rollup -c" }, "author": "Alex Eagleson", "license": "ISC", "devDependencies": { "@rollup/plugin-commonj
🌐
Yugensys
yugensys.com β€Ί home β€Ί react β€Ί how to bundle a react library into reusable components
How to Bundle a React Library into Reusable Components - Yugensys | Outsourced Product Development | IT Services
December 10, 2024 - From setting up the project structure to configuring bundlers like Webpack or Rollup, you’ll learn how to build modular, efficient, and maintainable React components ready for deployment. Welcome to our comprehensive guide on bundling a React library into a reusable component library!
🌐
Medium
medium.com β€Ί simform-engineering β€Ί building-a-component-library-with-react-typescript-and-storybook-a-comprehensive-guide-ba189accdaf5
Building a Component Library with React, Typescript, and Storybook: A Comprehensive Guide | by Ashish Kachhadiya | Simform Engineering | Medium
September 22, 2023 - This comprehensive guide covered essential tools and best practices for building a high-quality React component library β€” from project setup and testing to publishing, deployment, and local testing. Following these steps will enable you to create reusable, robust React components suitable for use across projects and teams.
🌐
OpenReplay
blog.openreplay.com β€Ί how-to-build-your-own-react-components-library
How to build your own React components library
March 23, 2023 - Package Description: Describe what the component you’re creating does. Author’s Github Handle: your Github handle. Gihub repo path: Repository for the library. License: Most times, you’d see MIT just hit enter button. Package manager: choose between NPM and YARN. Custom, typescript, or default templates are all acceptable (which is JavaScript).
🌐
Pluralsight
pluralsight.com β€Ί courses β€Ί react-creating-reusable-components
Creating Reusable React Components
In this course, Creating Reusable React Components, you'll explore over 50 decisions to consider when designing, creating, and publishing reusable React components, including atomic design, documentation generation, styling, theming, testing, packaging, and publishing. By the end of this course, you'll know how to publish and maintain your own reusable component library.
🌐
CTF Assets
assets.ctfassets.net β€Ί otcg69yadk3e β€Ί 2vQ7FxW1Ow2wQwmM02y6GG β€Ί 347338f925e7a42375655c7917351c5c β€Ί Building_a_Reusable_Component_Library_in_React.pdf pdf
Reusable Component Library in React Reduce, reuse… React!
Reusable Component Library Β· in React Β· Reduce, reuse… React! Who is this human? ● Β· Connor Wilson Β· ● Β· Front-end @ Tulip, Formerly Mappedin, recovering freelancer Β· ● Β· Instructor @ Bridge Β· ● Β· Socials on cwlsn.com, me@cwlsn.com Β· ● Β· Cat whisperer Β· What is this talk? ● Β· I built a boilerplate for creating a Component library, documented the Β·
🌐
Rapidcanvas
rapidcanvas.ai β€Ί home β€Ί blogs β€Ί creating a robust react component library with rollup, typescript, and storybook
Creating a Robust React Component Library with Rollup, TypeScript, and Storybook
June 25, 2024 - Run npm run storybook to launch the Storybook environment and visualize your components. Update the library version in package.json following the Semantic Versioning (SemVer) convention. Build the library for production with npm run rollup. Publish the library to a package registry like npm or a private registry. Rollup is a popular choice over other bundling tools like Webpack or Browserify for creating JavaScript libraries and components
🌐
LogRocket
blog.logrocket.com β€Ί home β€Ί how to build a component library with react and typescript
How to build a component library with React and TypeScript - LogRocket Blog
November 6, 2024 - In this article, we’ll guide you through building a custom React component library with TypeScript, covering essential steps such as: ... This approach will help you create a maintainable, reusable library that can evolve alongside your projects.
Find elsewhere
🌐
Prateeksurana
prateeksurana.me β€Ί blog β€Ί react-component-library-using-storybook-7
Creating a React component library using Storybook 7
May 14, 2023 - Let's add rollup, run the following to install Rollup and its plugins that we'll be using to bundle the library - yarn add --dev rollup @rollup/plugin-typescript @rollup/plugin-commonjs @rollup/plugin-node-resolve rollup-plugin-peer-deps-external rollup-plugin-postcss rollup-plugin-dts postcss Β· Now before we add the rollup config, there are a few types of JavaScript modules that you should be aware of - CommonJS - This module format is most commonly used with Node using the require function. Even though we are publishing a React module (which will be consumed by an application generally writ
🌐
GeeksforGeeks
geeksforgeeks.org β€Ί reactjs β€Ί how-to-create-an-npm-library-from-react-components
How to Create an NPM Library from React Components? - GeeksforGeeks
July 23, 2025 - Creating an NPM library from your React components is a great way to share reusable components across different projects. By following the steps outlined in this guide, you can bundle your components with Rollup, set up the necessary NPM ...
🌐
Quora
quora.com β€Ί How-can-I-create-a-react-components-library-so-that-I-could-reuse-those-components-separately-in-a-different-project-by-installing-this-library-using-NPM
How to create a react components library so that I could reuse those components separately in a different project by installing this library using NPM - Quora
Answer: it would be very difficult to explain everything you need to do in order to create a Reusable Components Library in just a few paragraphs, but I’m gonna recommend you an excellent PluralSight course which teaches you to do just that following all the best practices: Creating Reusable Rea...
🌐
freeCodeCamp
freecodecamp.org β€Ί news β€Ί how-to-create-a-truly-reusable-react-component-from-scratch
How to Create a Truly Reusable React Component from Scratch
August 20, 2021 - If you want to learn Redux in detail from scratch and build 3 apps along with the complete food ordering app, check out the Mastering Redux course. ... How to use Redux in React using the react-redux library to make your app reactive.
🌐
Retool
docs.retool.com β€Ί build apps β€Ί how-to β€Ί custom content β€Ί custom components
Build custom React components | Retool Docs
Custom component libraries only load JavaScript and CSS files at runtime. Any other file included in the revision bundle is ignored. Node.js v20 or later is required for your development environment. Admin permissions in Retool are required. Custom components must be written in React and Typescript.
🌐
Medium
hinammehra.medium.com β€Ί build-a-private-react-component-library-cra-rollup-material-ui-github-package-registry-1e14da93e790
Build a Private React Component Library (with a live playground) | Medium
September 25, 2021 - In this tutorial, we are just going to set-up the foundations of our component library with a HelloWorld component. In a directory of your choice, create a simple react app:
🌐
UXPin
uxpin.com β€Ί home β€Ί how to build reusable react components
How to Build Reusable React Components | UXPin
October 16, 2025 - Creating reusable React components becomes more efficient with tools designed to bridge the gap between design and development. UXPin simplifies the process of building, testing, and deploying code-backed React components. It lays the groundwork for integrating libraries, interactive testing, and smooth collaboration between design and development teams.
🌐
Medium
suryashakti1999.medium.com β€Ί building-your-own-component-library-and-why-i-did-it-2ecc06db9330
πŸ’‘ Building Your Own Component Library (And Why I Did It) | by Surya Shakti | Medium
July 19, 2025 - my-component-library/ β”œβ”€β”€ src/ β”‚ β”œβ”€β”€ components/ β”‚ β”‚ β”œβ”€β”€ Button/ β”‚ β”‚ β”‚ β”œβ”€β”€ Button.tsx β”‚ β”‚ β”‚ β”œβ”€β”€ Button.stories.tsx β”‚ β”‚ β”‚ └── index.ts β”‚ β”‚ β”œβ”€β”€ Modal/ β”‚ β”‚ └── Input/ β”‚ β”œβ”€β”€ utils/ β”‚ └── index.ts β”œβ”€β”€ tailwind.config.js β”œβ”€β”€ package.json └── tsconfig.json Β· Here’s an example of a reusable Button component: import React from 'react'; import clsx from 'clsx';
Top answer
1 of 2
2

After a lot of playing around I managed to produce the wanted result with rollup. The only downside of the current configuration is that it does not support newly added files in the --watch mode. The magic setting is under the output.preserveModules

Config:

// rollup.config.js
import commonjs from '@rollup/plugin-commonjs';
import typescript from '@rollup/plugin-typescript';
import postcss from 'rollup-plugin-postcss';
import postcssUrl from 'postcss-url';
import resolve from "@rollup/plugin-node-resolve";

import peerDepsExternal from "rollup-plugin-peer-deps-external";

export default {
    input: 'src/index.tsx',
    output: {
        dir: 'dist',
        format: 'es',
        preserveModules: true,
        sourcemap: true,
    },
    plugins: [
        resolve(),
        peerDepsExternal(),
        commonjs(),

        typescript({
            tsconfig: 'tsconfig.build.json'
        }),
        postcss({
            minimize: true,
            modules: {
                generateScopedName: "[hash:base64:5]"
            },
            plugins: [
                postcssUrl({
                    url: "inline"
                })
            ]
        }),

    ],
};

I hope this config can help others as well

2 of 2
0

You can checkout this repo. I made some changes for building a lib.

https://github.com/21paradox/react-webpack-typescript-starter

To use a library like below:

import Input from 'my-custom-ui/entry/Input';
import { Input } from 'my-custom-ui';

After doing a lot of searching, I ended up writing a plugin to manually generate the webpack entry code that webpack needed (for building a ui library).

The multiple entry + manualy generated entry file seems to be working for component seperate & no redudant code. This is also very helpful if you want to build a vue based libray.

🌐
AlmaBetter
almabetter.com β€Ί bytes β€Ί tutorials β€Ί reactjs β€Ί reusable-components-in-react
Building Reusable Components in React JS
By following the principles of ReactJS component design, developers can create high-quality components that are easy to understand and use. Designing reusable components involves identifying the functionality that needs to be reusable, defining the interface, implementing the component, testing it, and documenting it. Sharing and reusing components is made easy in ReactJS through the use of npm packages, component libraries, and code repositories.
🌐
Medium
medium.com β€Ί edf-data-and-tech β€Ί setting-up-a-react-component-library-492ff08f4d7f
Setting up a React component library | by Joey Imlay | EDF Data and Tech | Medium
August 6, 2024 - Vite uses Rollup as its bundler, ... Speaking of CSS, any styling system will work here. To create the project, run yarn create vite....
🌐
Medium
medium.com β€Ί hackernoon β€Ί creating-a-library-of-react-components-using-create-react-app-without-ejecting-d182df690c6b
Creating a library of React components using Create React App | by Aakash | HackerNoon.com | Medium
December 18, 2018 - Creating a library of React components using Create React App UPDATE: You can use the npm package create-component-lib to automate all the steps described in this blog …