Does anyone know of a nice starting template for a React component npm package?
I want to make a React component and publish it to NPM but cba setting it up myself and invent the wheel again. Is there a nice starting point for this that I can use? Needs TypeScript of course. Maybe Vite or something for dev.
4 Replies
Vite is absolutely a good option: https://vitejs.dev/guide/build.html#library-mode
I've used tsup a couple of times as well. That too works great.
Yeah, I know of those options. I just wanted a more complete setup for a package. With a tsup config for cjs/esm, types, a playground, testing, etc
I actually made a template repo for creating a library using Typescript, Vite, and Vitest, with ESLint and Prettier already configured. There's even CI via GitHub actions and version managing through changesets. It uses pnpm as a package manager, but npm works too just by deleting pnpm's package lock file. Sorry if this isn't what you're looking for and my self-promotion is just plain bad.
Here's the link: https://github.com/ben-laird/typelaunch
GitHub
GitHub - ben-laird/typelaunch: An opinionated template to launch a ...
An opinionated template to launch a TypeScript library with best practices - GitHub - ben-laird/typelaunch: An opinionated template to launch a TypeScript library with best practices
To add in React support, run
pnpm i -D @vitejs/plugin-react
and any peers, then add the Vite React plugin to the plugins array in vite.config.ts