kn-componentlibrary
v0.0.2
Published
react component library
Readme
componentlibrary
This repository documents my learning process in developing a custom React component library. It includes experiments, code examples, and best practices.
1. Project Setup
- Create a new folder:
mkdir componentlibrary && cd componentlibrary - Initialize npm:
npm init -y - Install dependencies:
npm install react typescript tslibnpm install rollup @rollup/plugin-node-resolve @rollup/plugin-commonjs @rollup/plugin-typescript @rollup/plugin-peer-deps-external @rollup/plugin-terser rollup-plugin-dts --save-devnpm install rollup-plugin-postcss --save-devnpm install @types/react --save-dev
- Create TypeScript configuration:
npm tsc --init - Create project structure:
- Create
srcfolder - Inside
src, createcomponentsfolder - Create
src/index.ts
- Create
2. Development (example)
- Create a component file:
src/components/Button/Button.tsx - (Implement your component logic)
3. Build & Publish
- Run Rollup to build the library:
npm run rollup(you'll need to create arollup.config.jsfile) - Publish to npm:
npm loginnpm publish
4. Usage in another project
- Install the library:
npm i kn-componentlibrary
Base Version Commit
- Commit the initial project setup, including
package.json,tsconfig.json,rollup.config.js, and basic component structure. - Add a note to the commit message describing the initial setup and the purpose of the library.
- Push the commit to your Git repository.
