npm 私服 - childlabor/blog GitHub Wiki
npm官方托管,开源免费,私有包需付费7刀/月。因此如果不打算开源项目,需要建立一个npm私服。
选型一
verdaccio,一个开源轻量的npm私服。
要求:
- Node 版本10+
- npm >=5.x
- Web 界面支持 Chrome, Firefox, Edge, 和 IE11 浏览器。
使用:
- 安装
$ npm install --global verdaccio
- 启动服务
$ verdaccio
// 配置ip访问
$ verdaccio -l 192.168.31.165:4873
- 添加用户
$ npm adduser --registry http://localhost:4873
cd到私有库
- 发布私有库
$ npm publish --registry http://localhost:4873
cd到项目
- 安装私有库
$ npm install <package name> --registry http://localhost:4873
可视化界面:
打开http://localhost:4873
可以查看UI界面,点击对应包可进入查看README文档。
PS: 部署也有官方的 Docker 镜像可供使用。
选型二
通过npm+git
的方式直接安装git私有仓库的项目。
// 示例
$ npm install git+https://github.com/childlabor/repo-component.git
or
$ npm install git+ssh://[email protected]:childlabor/repo-component.git
总结
推荐使用verdaccio。部署简单方便,方便模块集中管理,权限控制等。