有几种方法可以测试 pnpm publish
而不实际发布到 npm:
- 使用
--dry-run
选项
bash
pnpm publish --dry-run
这会模拟发布过程,显示将要发布的内容,但不会真正发布。
- 使用私有的 npm registry(推荐)
使用 Verdaccio 搭建本地 registry:
bash
# 安装 verdaccio
pnpm add -g verdaccio
# 启动本地 registry
verdaccio
# 设置 npm registry 为本地地址
npm set registry http://localhost:4873/
# 创建新用户
npm adduser --registry http://localhost:4873/
# 发布包
pnpm publish --registry http://localhost:4873/
- 使用
private
字段防止意外发布
json
{
"private": true, // 添加这个字段会阻止包被发布
"name": "@my-scope/my-package",
"version": "1.0.0"
}
- 使用
.npmrc
配置发布目标
ini
registry=http://localhost:4873/
# localhost:4873/:_authToken="your-token"
测试完成后,记得:
bash
# 恢复到 npm 官方源
npm set registry https://registry.npmjs.org/
使用 Verdaccio 的好处是:
- 可以完整测试发布流程
- 可以测试包的安装和依赖
- 不会污染 npm 官方源
- 可以测试私有包的发布流程