Unified dependency aggregation layer for shared libraries
npm install tcdona_unilib一个统一的依赖管理库,支持通过子路径导入,保持 tree-shaking 能力。
- ✅ ESM 模块(type: module)
- ✅ 子路径导入支持(如 import from 'tcdona_unilib/zod')
- ✅ Tree-shaking 优化
- ✅ 完整的类型支持
- ✅ 统一的版本管理
``bash`
npm install tcdona_unilibor
yarn add tcdona_unilibor
pnpm add tcdona_unilib
`typescript
// 导入单个库
import { z } from "tcdona_unilib/zod"
import { nanoid } from "tcdona_unilib/nanoid"
import dayjs from "tcdona_unilib/dayjs"
import { defineConfig } from "tcdona_unilib/vite"
// 导入所有库
import * as tcdona_unilib from "tcdona_unilib"
`
| 库名 | 导入方式 | 用途 |
| ---------- | -------------------------- | ---------- |
| neverthrow | tcdona_unilib/neverthrow | 错误处理 |tcdona_unilib/zx
| zx | | Shell 脚本 |tcdona_unilib/dayjs
| dayjs | | 日期时间 |tcdona_unilib/big.js
| big.js | | 精确算术 |tcdona_unilib/estk
| es-toolkit | | ES 工具集 |
``
tcdona_unilib/
├── package.json # 统一依赖声明
├── tsconfig.json # TypeScript 配置
├── index.ts # 全量导出入口
├── neverthrow.ts # 子路径模块
├── zod.ts
├── ... (其他 20 个库)
└── README.md
- exports 字段: 定义子路径映射关系,支持 tcdona_unilib/zod 导入方式
- type: module: 启用 ESM 模块系统
- Tree-shaking: 每个模块仅做简单转发,构建工具可自动优化
要添加新库,只需:
1. 在 package.json 的 dependencies 中添加库及版本exports
2. 在 中添加路径映射*.ts
3. 创建对应的 转发文件:`
typescript`
export { method } from "your-library"
export *
禁止用 index.ts
4. 在 中添加导出行
所有依赖版本统一在 package.json` 中管理,确保项目内一致性。