便捷工具方法
Go to file
CodiceFabbrica b10d613987 feat(common): 添加工具 2026-04-20 17:54:26 +08:00
.claude feat(common): 添加工具 2026-04-20 17:54:26 +08:00
.gitee docs: 📝 配置git规范 2026-03-17 17:36:55 +08:00
.github docs: 📝 配置git规范 2026-03-17 17:36:55 +08:00
.husky feat(): 改为vite 2026-03-16 17:58:57 +08:00
.serena feat(common): 添加工具 2026-04-20 17:54:26 +08:00
.vscode feat(common): 添加工具 2026-04-20 17:54:26 +08:00
docs docs: 📝 配置git规范 2026-03-17 17:36:55 +08:00
packages feat(common): 添加工具 2026-04-20 17:54:26 +08:00
scripts feat(common): 添加工具 2026-04-20 17:54:26 +08:00
.czrc feat(common): 添加input-rules 2026-03-18 15:52:07 +08:00
.editorconfig ci: 🎡 配置.ps1文件的编码及换行符 2026-03-18 16:41:54 +08:00
.gitattributes ci: 🎡 配置.ps1文件的编码及换行符 2026-03-18 16:41:54 +08:00
.gitignore feat(common): 添加工具 2026-04-20 17:54:26 +08:00
.lintstagedrc.json feat(common): 添加工具 2026-04-20 17:54:26 +08:00
.npmrc feat(common): 添加工具 2026-04-20 17:54:26 +08:00
.prettierignore feat(): 改为vite 2026-03-16 17:58:57 +08:00
.versionrc.json ci: 🎡 publish分离版本号更新 2026-03-18 16:32:27 +08:00
CHANGELOG.md chore(release): 1.2.1 2026-03-26 08:56:15 +08:00
CLAUDE.md ci: 🎡 publish分离版本号更新 2026-03-18 16:32:27 +08:00
LICENSE Initial commit 2023-04-20 01:26:40 +00:00
README.md feat(common): 添加工具 2026-04-20 17:54:26 +08:00
commitlint.config.cjs feat(common): 添加工具 2026-04-20 17:54:26 +08:00
eslint.config.js feat(common): 添加工具 2026-04-20 17:54:26 +08:00
package.json feat(common): 添加工具 2026-04-20 17:54:26 +08:00
pnpm-lock.yaml feat(common): 添加工具 2026-04-20 17:54:26 +08:00
pnpm-workspace.yaml feat(common): 添加工具 2026-04-20 17:54:26 +08:00
prettier.config.js feat(common): 添加工具 2026-04-20 17:54:26 +08:00
tsconfig.base.json feat(): 更新依赖 2026-03-17 14:42:03 +08:00
tsconfig.eslint.json feat(common): 添加工具 2026-04-20 17:54:26 +08:00
tsconfig.json feat(common): 添加工具 2026-04-20 17:54:26 +08:00
vitest.config.ts feat(common): 添加工具 2026-04-20 17:54:26 +08:00

README.md

r-utils

前端工具库 monorepo使用 pnpm workspace 管理Vite 构建。

包列表

包名 路径 描述
@r-utils/common packages/common 通用 JS/TS 工具(权限、倒计时、打印、时间等)
@r-utils/vue3 packages/vue3 Vue3 工具class 处理、dispatch 等)
@r-utils/uni-app packages/uni-app uni-app 工具请求封装、蓝牙、NFC、打印等
@r-utils/uview-plus packages/uview-plus uview-plus 组合式 API HooksPicker、Calendar 等)
@r-utils/vue2 packages/vue2 Vue2 工具visibility 插件)

环境要求

  • Node.js >= 18.12.0
  • pnpm >= 8.15.6

安装依赖

pnpm install

构建

构建所有包

pnpm build

构建单个包

cd packages/common
pnpm build

每个包使用 Vite lib 模式构建,输出到 dist/ 目录:

dist/
├── index.mjs       # ESM 格式
├── index.cjs       # CJS 格式
├── index.d.ts      # TypeScript 类型声明
├── index.mjs.map   # Source Map
└── index.cjs.map

监听模式

cd packages/common
pnpm watch

使用方式

ESM 引入(推荐)

支持 tree-shaking打包工具会自动按需引入用到的部分。

// 完整引入
import { Permission, Countdown, KnockTest } from '@r-utils/common';

// 按需引入bundler 自动 tree-shaking只打包 Permission
import { Permission } from '@r-utils/common';

// Vue3 工具
import { mergeClass, dispatch } from '@r-utils/vue3';

// uni-app 工具
import { Request } from '@r-utils/uni-app';

// uview-plus Hooks
import { usePickerSingle, usePicker, useCalendar } from '@r-utils/uview-plus';

// Vue2 插件
import { VisibilityPlugin } from '@r-utils/vue2';
Vue.use(VisibilityPlugin);

CJS 引入

const { Permission } = require('@r-utils/common');

package.json exports

每个包均配置了标准的 exports 字段,打包工具会自动选择正确的格式:

{
  "exports": {
    ".": {
      "types": "./dist/index.d.ts",
      "import": "./dist/index.mjs",
      "require": "./dist/index.cjs"
    }
  }
}

开发

测试

# 运行所有测试
pnpm test

# 运行单个测试文件
npx jest packages/common/test/permission.test.ts

代码检查与格式化

pnpm lint
pnpm format

Git 提交

项目使用 Conventional Commits 规范,通过 commitizen + cz-git 提供交互式提交体验。

# 使用交互式提交(推荐)
pnpm commit

提交时 husky 会自动运行:

  • lint-staged - 代码检查和格式化
  • jest - 单元测试
  • commitlint - 提交信息格式校验

详细说明请参考 提交规范指南

发布

1. 版本管理standard-version

使用 standard-version 更新版本号、生成 CHANGELOG、创建 Git commit 和 tag。版本配置见 .versionrc.json,会同步更新根包和所有子包的版本号。

# 默认 patch 版本
pnpm release

# 指定版本类型
npx standard-version --release-as minor   # 1.0.0 -> 1.1.0
npx standard-version --release-as major   # 1.0.0 -> 2.0.0

2. 构建并发布到私有 npm 仓库

项目已配置发布到私有 npm 仓库 http://npm.nps.yunvip123.cn

Windows (PowerShell)

powershell scripts/publish.ps1

Linux/macOS (Bash)

bash scripts/publish.sh

发布脚本会自动执行以下步骤:

  1. 检查 Git 工作区状态
  2. 运行测试(确保代码质量)
  3. 构建所有子包
  4. 依次发布 @r-utils/common@r-utils/vue3@r-utils/uni-app@r-utils/vue2
  5. 询问是否推送到远程仓库

安装已发布的包

# 配置 npm registry
npm config set registry http://npm.nps.yunvip123.cn

# 或在项目中使用 .npmrc 文件
echo "registry=http://npm.nps.yunvip123.cn" > .npmrc

# 安装包
pnpm add @r-utils/common
pnpm add @r-utils/vue3
pnpm add @r-utils/uni-app
pnpm add @r-utils/uview-plus
pnpm add @r-utils/vue2

项目结构

r-util-js/
├── packages/
│   ├── common/          # @r-utils/common
│   │   ├── src/
│   │   │   ├── permission/   # Permission 权限校验
│   │   │   ├── timer/        # Countdown、TimeoutTimer
│   │   │   ├── printer/      # ESC/TSC 打印指令
│   │   │   ├── knock-test/   # KnockTest 敲击触发
│   │   │   └── time/         # 时间工具
│   │   ├── vite.config.ts
│   │   └── tsconfig.json
│   ├── vue3/            # @r-utils/vue3
│   ├── uni-app/         # @r-utils/uni-app
│   ├── uview-plus/      # @r-utils/uview-plus
│   └── vue2/            # @r-utils/vue2
├── eslint.config.js     # ESLint v9 flat config
├── prettier.config.js
└── pnpm-workspace.yaml

参与贡献

欢迎贡献代码!请先阅读:

基本流程:

  1. Fork 本仓库
  2. 新建分支 feat/xxxfix/xxx
  3. 提交代码(使用 pnpm commit)
  4. 新建 Pull Request