⚛️ Production-ready React library template with TypeScript, Storybook, automated testing, and optimized builds with tree-shaking and code splitting.
- TypeScript - Full type safety with modern TS features and React support
- tsup - Fast, zero-config bundler powered by esbuild with tree-shaking and code splitting
- Vitest - Fast unit testing with React Testing Library
- Storybook - Component development environment with visual testing
- Changesets - Automated version management and changelog generation
- GitHub Actions - Automated CI/CD workflows for testing and publishing
- Pre-publish safety - Automatic checks before publishing to prevent broken releases
pnpm install
pnpm test
- Add React components in
src/
- Create Storybook stories alongside your components (e.g.,
component.stories.tsx
) - Add tests in
tests/
- Update
package.json
metadata (name, description, keywords, repository)
Automatic tree-shaking and code splitting ensure consumers only bundle what they use. Import components either from the main entry point or directly from individual paths:
// Main entry point
import { Button } from '@ras-sh/template-react-library';
// Direct import
import { Button } from '@ras-sh/template-react-library/button';
Command | Description |
---|---|
pnpm build |
Build library with tsup |
pnpm test |
Run tests with vitest |
pnpm test:coverage |
Run tests with coverage report |
pnpm storybook |
Start Storybook dev server |
pnpm build-storybook |
Build Storybook for deployment |
pnpm check-types |
Run TypeScript type checking |
pnpm check |
Run linter checks |
pnpm fix |
Auto-fix linting issues |
pnpm changeset |
Create a new changeset |
pnpm version |
Update versions based on changesets |
pnpm release |
Build and publish to npm |
src/
├── button.tsx # Example Button component
├── button.stories.tsx # Storybook stories for Button
├── index.ts # Main entry point
tests/
├── setup.ts # Test setup with jest-dom
├── button.test.tsx # Component tests
.storybook/
├── main.ts # Storybook configuration
├── preview.ts # Storybook preview config
├── vitest.setup.ts # Storybook Vitest integration
.github/
├── workflows/
│ ├── ci.yml # CI workflow (lint, test, build)
│ └── release.yml # Automated release workflow
├── ISSUE_TEMPLATE/
│ ├── bug_report.yml # Bug report template
│ └── feature_request.yml # Feature request template
└── PULL_REQUEST_TEMPLATE.md # PR template
This template includes automated GitHub Actions workflows:
-
CI Workflow - Runs on every PR and push to main
- Linting with Biome
- Type checking with TypeScript
- Unit tests with Vitest
- Build verification
-
Release Workflow - Automated publishing with Changesets
- Creates version bump PRs automatically
- Publishes to npm when merged
To enable automated npm publishing, add an NPM_TOKEN
secret to your GitHub repository:
- Create an npm access token at npmjs.com
- Go to your GitHub repository settings → Secrets and variables → Actions
- Add a new secret named
NPM_TOKEN
with your npm token
This template uses Changesets for version management.
-
Create a changeset when you make changes:
pnpm changeset
Follow the prompts to describe your changes (patch, minor, or major).
-
Commit and push your changes including the changeset file
-
Automated workflow will:
- Create a "Version Packages" PR with version bumps and changelog
- When you merge that PR, automatically publish to npm
You can also publish manually:
pnpm version # Update versions from changesets
pnpm release # Build and publish to npm
Note: The
prepublishOnly
script ensures all checks pass before publishing.
MIT License - see the LICENSE file for details.