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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@golf-h/r-button

v1.0.0

Published

基于 Vite 封装的 React Button 组件

Readme

r-button

基于 Vite 封装 React Button 组件 (带测试、文档、打包、发布全流程)

环境要求

  • Node.js 20.19 或以上版本
  • npm 或 yarn 包管理器
  • react 18.2 或以上版本

初始化vite+react+typescript项目

# 初始化项目
npm create vite@latest r-button -- --template react-ts
# 进入项目目录
cd r-button
# 安装依赖
npm install

组件开发

  • 类型定义
  • 功能、样式
  • 导出

组件测试

使用 vitest(Vite 生态推荐,配置简单)+ @testing-library/react 进行组件测试,确保组件功能稳定性。

安装依赖

npm install -D vitest @testing-library/react @testing-library/jest-dom jsdom @types/testing-library__jest-dom

配置 vitest

修改vite.config.ts,添加测试选项

编写组件测试用例

src/components/Button/Button.test.tsx

执行测试

组件文档

建议使用 Storybook(前端组件文档工具,适配 React/Vite)生成组件文档,方便他人查阅和使用。

组件打包

Vite 默认打包为应用程序,需要修改配置,打包为 可复用的库模式(Library Mode),生成符合 NPM 规范的产物(ES Module + CommonJS)。

  • 修改 vite.config.ts,添加库模式打包选项
  • 修改 package.json,添加导出选项
  • 修改 tsconfig.json

组件发布

  • npm login 登录
  • npm pack 发布前检查
  • npm publish --access=public 发布