Skip to content

A modern, production-ready boilerplate for building React component libraries. This project provides a complete development environment with Rollup bundling, TypeScript support, Storybook for component documentation, and comprehensive testing setup.

License

Notifications You must be signed in to change notification settings

KaiHotz/react-rollup-boilerplate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

React Rollup Boilerplate

License: MIT Node.js Version React TypeScript Rollup Storybook

A modern, production-ready boilerplate for building React component libraries. This project provides a complete development environment with Rollup bundling, TypeScript support, Storybook for component documentation, and comprehensive testing setup.

✨ Features

  • βš›οΈ React 19.2 - Built with the latest React version
  • πŸ“¦ Rollup Bundler - Optimized ES modules output for tree-shaking
  • πŸ”· TypeScript - Full TypeScript support with type declarations
  • πŸ“š Storybook 10 - Interactive component documentation and development
  • πŸ§ͺ Vitest - Fast unit testing with React Testing Library
  • 🎨 SCSS Support - Styling with SCSS and CSS modules
  • βœ… ESLint & Prettier - Code linting and formatting
  • 🎯 Stylelint - CSS/SCSS linting with BEM methodology
  • πŸ“± Accessibility - JSX a11y plugin for accessibility best practices

πŸ“ Project Structure

react-rollup-boilerplate/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ components/          # React components
β”‚   β”‚   β”œβ”€β”€ Button/          # Example Button component
β”‚   β”‚   β”‚   β”œβ”€β”€ Button.tsx
β”‚   β”‚   β”‚   β”œβ”€β”€ Button.scss
β”‚   β”‚   β”‚   β”œβ”€β”€ Button.test.tsx
β”‚   β”‚   β”‚   β”œβ”€β”€ Button.stories.tsx
β”‚   β”‚   β”‚   └── index.ts
β”‚   β”‚   β”œβ”€β”€ Tabs/            # Example Tabs component
β”‚   β”‚   β”‚   β”œβ”€β”€ Tabs.tsx
β”‚   β”‚   β”‚   β”œβ”€β”€ Tab.tsx
β”‚   β”‚   β”‚   β”œβ”€β”€ TabPanel.tsx
β”‚   β”‚   β”‚   β”œβ”€β”€ TabsList.tsx
β”‚   β”‚   β”‚   β”œβ”€β”€ context.ts
β”‚   β”‚   β”‚   β”œβ”€β”€ *.scss
β”‚   β”‚   β”‚   β”œβ”€β”€ Tabs.stories.tsx
β”‚   β”‚   β”‚   └── index.ts
β”‚   β”‚   └── index.ts         # Component exports
β”‚   └── index.ts             # Main library entry point
β”œβ”€β”€ dist/                    # Built library output
β”œβ”€β”€ storybook-static/        # Built Storybook for deployment
β”œβ”€β”€ rollup.config.mjs        # Rollup bundler configuration
β”œβ”€β”€ tsconfig.json            # TypeScript configuration
β”œβ”€β”€ vitest.config.ts         # Vitest test configuration
β”œβ”€β”€ eslint.config.js         # ESLint configuration
└── .stylelintrc.cjs         # Stylelint configuration

πŸš€ Getting Started

Prerequisites

  • Node.js >= 18
  • Yarn package manager

Installation

Clone the repository

git clone git@github.com:KaiHotz/react-rollup-boilerplate.git
cd react-rollup-boilerplate
yarn install

Or download directly

Download the .zip file, extract it, then:

cd react-rollup-boilerplate
yarn install

πŸ’» Development

Start the development environment with Storybook:

yarn start

This launches Storybook at http://localhost:6006, where you can:

  • View and interact with your components
  • Test different props and states
  • Document component usage

Creating Components

  1. Create a new folder in src/components/ with your component name
  2. Add your component files:
    • YourComponent.tsx - Component implementation
    • YourComponent.scss - Component styles
    • YourComponent.test.tsx - Unit tests
    • YourComponent.stories.tsx - Storybook stories
    • index.ts - Component export
  3. Export your component from src/components/index.ts

Refer to the Button and Tabs components as examples.

🎨 Styling

SCSS & CSS Support

Import styles directly into your components:

import './YourComponent.scss';

CSS Modules

For CSS Modules support, refer to rollup-plugin-postcss.

Style Linting

SCSS and CSS are linted using Stylelint with BEM methodology:

yarn stylelint        # Check styles
yarn stylelint:fix    # Auto-fix style issues

πŸ” Linting & Formatting

TypeScript/JavaScript

Code quality is enforced via ESLint and Prettier:

yarn lint         # Run all linters (ESLint, Stylelint, TypeScript)
yarn lint:fix     # Auto-fix all linting issues
yarn eslint       # Run ESLint only
yarn eslint:fix   # Auto-fix ESLint issues
yarn check-types  # Run TypeScript type checker

Customize rules in eslint.config.js.

πŸ§ͺ Testing

Testing is powered by Vitest and React Testing Library:

yarn test              # Run tests in watch mode
yarn test:coverage     # Run tests with coverage report

See Button.test.tsx for example test patterns.

πŸ“¦ Building

Build your library for production:

yarn build

Output is generated in the dist/ folder with:

  • ES modules for modern bundlers
  • TypeScript type declarations

🚒 Publishing

To NPM or Private Registry

  1. Ensure you have an active NPM account
  2. Configure your .npmrc file
  3. Update publishConfig.registry in package.json
  4. Run:
yarn release

This runs linting, tests, builds, and publishes your library.

πŸ“š Storybook

Development

yarn storybook

Build Static Storybook

yarn storybook:build

Output is generated in storybook-static/.

Deploy to GitHub Pages

Update the homepage URL in package.json, then:

yarn storybook:deploy

For more information, see the Storybook documentation.

πŸ“œ Available Scripts

Script Description
yarn start Start Storybook development server
yarn build Build library to dist/ folder
yarn test Run tests in watch mode
yarn test:coverage Run tests with coverage report
yarn lint Run all linters (ESLint, Stylelint, TypeScript)
yarn lint:fix Auto-fix all linting issues
yarn eslint Run ESLint only
yarn eslint:fix Auto-fix ESLint issues
yarn stylelint Run Stylelint only
yarn stylelint:fix Auto-fix Stylelint issues
yarn check-types Run TypeScript type checker
yarn ci Run linting and tests (for CI/CD)
yarn release Lint, test, build, and publish to NPM
yarn storybook Start Storybook
yarn storybook:build Build static Storybook
yarn storybook:deploy Deploy Storybook to GitHub Pages

πŸ› οΈ Tech Stack

Core

Bundling

Development

  • Storybook 10 - Component development environment
  • Vite - Development server for Storybook

Testing

Code Quality

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ‘€ Author

Kai Hotz

🀝 Contributing

Contributions, issues, and feature requests are welcome! Feel free to check the issues page.

About

A modern, production-ready boilerplate for building React component libraries. This project provides a complete development environment with Rollup bundling, TypeScript support, Storybook for component documentation, and comprehensive testing setup.

Topics

Resources

License

Stars

Watchers

Forks

Contributors 7