npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@sasibhumaraju/create-react-component-library

v3.0.7

Published

Teamplate for creating react coponent library - (starter code)

Downloads

1

Readme

Create React Component Library

Create React Component Library Logo

This is a starter template for creating a React component library. It comes pre-configured with Rollup for bundling, Babel for transpiling, and Storybook for interactive component development and documentation. Ideal for developers who want to build reusable UI components for React applications, this template simplifies the process of creating, building, and publishing React component libraries. 🚀

Features ✨

  • 📦 Bundling with Rollup: Package your components efficiently for both CommonJS and ES module formats.
  • 🛠 Transpiling with Babel: Use modern ES6+ and JSX syntax, ensuring compatibility across environments.
  • 📚 Storybook Integration: Document and test your components in isolation with live previews.
  • 🎨 CSS Modules: Scoped styling with PostCSS support.
  • 🔄 PropTypes and TypeScript Support: Type-check your props and ensure proper usage.

Installation ⚙️

To get started, simply run the following command:

npx create-react-component-library

Scripts

Here's a list of the most important scripts included in the template:

  • Start Storybook: Run Storybook to develop and preview your components interactively.

    npm start

    This will open Storybook in your browser at http://localhost:6006.

  • Build the Library: Bundle your components into distributable formats.

    npm run build-lib

    This will output your library to the dist/ folder, creating both CommonJS and ESM versions.

Folder Structure 🗂️

After running the starter, the basic folder structure will look like this:

├── dist/                     # Compiled and bundled files
├── src/                      # Source files (React components)
│   └── index.jsx             # Entry point for your library
├── .storybook/               # Storybook configuration
├── rollup.config.js          # Rollup bundling configuration
├── package.json              # Project configuration and dependencies
└── README.md                 # Project documentation

Example Component

To add a component to your library, create it under the src/ folder. Here's an example Button.jsx component:

import React from 'react';
import PropTypes from 'prop-types';
import './Button.css';

export const Button = ({ label, onClick, primary }) => (
  <button
    className={primary ? 'btn-primary' : 'btn-secondary'}
    onClick={onClick}
  >
    {label}
  </button>
);

Button.propTypes = {
  label: PropTypes.string.isRequired,
  onClick: PropTypes.func,
  primary: PropTypes.bool,
};

Building Your Library

To bundle the library and make it distributable, run:

npm run build-lib

The bundled files will appear in the dist/ folder. These files are ready for use in other projects or publishing to npm.

Publishing to npm 📦

To publish your library on npm:

  1. Ensure your package name in package.json is unique.

  2. Run the following command to log in to npm:

    npm login
  3. Publish the package:

    npm publish

Developers can now install your library in their projects using:

npm install your-library-name

Storybook 📚

Storybook is set up in this template for interactive component development. To run Storybook locally, use:

npm start

This will open the Storybook dashboard where you can view and interact with your components. You can add stories for new components under the src/stories/ folder.

Dependencies and DevDependencies 🔧

Peer Dependencies

  • react: Ensures the consuming project provides React.
  • react-dom: Provides DOM-specific methods for React.

DevDependencies

  • @babel/plugin-transform-runtime: Optimizes Babel's runtime helpers.
  • @rollup/plugin-node-resolve: Helps Rollup find node_modules.
  • rollup-plugin-postcss: Adds support for processing CSS files.
  • Storybook: Provides a UI for developing and testing components in isolation.

Example package.json

{
  "name": "react-component-library",
  "version": "1.0.0",
  "description": "Template for creating React component libraries",
  "main": "dist/index.jsx",
  "module": "dist/index.es.js",
  "scripts": {
    "start": "storybook dev -p 6006",
    "build-lib": "rollup -c"
  },
  "author": "@sasibhumaraju",
  "license": "MIT",
  "devDependencies": {
    "@babel/plugin-transform-runtime": "^7.25.4",
    "@babel/preset-react": "^7.24.7",
    "@babel/runtime": "^7.25.6",
    "rollup": "^4.22.0",
    "rollup-plugin-peer-deps-external": "^2.2.4",
    "rollup-plugin-postcss": "^4.0.2",
    "storybook-css-modules-preset": "^1.1.1",
    "@storybook/react-vite": "^8.3.2",
    "@storybook/addon-essentials": "^8.3.2"
  },
  "peerDependencies": {
    "prop-types": "^15.8.1",
    "react": "^18.3.1",
    "react-dom": "^18.3.1"
  }
}

Author 🤵

License 📜

This project is licensed under the MIT License.