公司出於自身隱私保護須要,不想把本身的代碼開源到包管理區,可是又急需一套完整包管工具,來管理愈來愈多的組件、模塊和項目。對於前端,最熟悉的莫過於npm,bower等;可是bower的市場兼容性明顯沒有npm強壯,加之commonjs規範的日益成熟。npm應該是前端包管理的不二選擇。前端
公司對於搭建本地私有npm庫有以下要求:node
node + npm + verdaccio + pm2 + nrmgit
Sinopia Verdaccio是一個零配置的私有的帶緩存功能的npm包管理工具github
PS: Sinopia多年未更新,Verdaccio是基於Sinopia重構的,注入了更多活力web
# config
$ /home/ubuntu/.config/verdaccio/config.yaml
# password
$ /home/ubuntu/web_npm/verdaccio/htpasswd
# storage
$ /home/ubuntu/web_npm/verdaccio/storage
複製代碼
pm2 託管Sinopia進程能夠保證進程永遠存活 nrm 便於查看和切換當前使用的registry verdaccio-delegated-auth 是爲了讓服務支持自定義驗證的插件docker
# Sinopia config.yaml
# path to a directory with all packages
storage: /home/ubuntu/web_npm/verdaccio/storage
auth:
# htpasswd:
# file: ./htpasswd
# max_users: -1
# mix_users: 1000
delegated-auth:
url: https://your-account-server/
user_key: name # username field, default: username
pwd_key: password # password field, default: password
# a list of other known repositories we can talk to
uplinks:
npmjs:
url: http://registry.npm.taobao.org/
packages:
'@company/*':
# scoped packages
access: $authenticated
publish: $authenticated
'*':
# keywords: "$all", "$anonymous", "$authenticated"
access: $all
publish: $all
proxy: npmjs
# log settings
logs:
- {type: stdout, format: pretty, level: http}
#- {type: file, path: sinopia.log, level: info}
listen: 0.0.0.0:4873
複製代碼
max_users: -1
,採用服務端提供用戶帳戶配置file: ./htpasswd
的方式新增用戶。@company/${app}
,例如@company/lodash
。前綴包@company/*
必須通過帳戶驗證後才能正常執行安裝或發佈。(company
指公司名稱)nrm
新增私有服務代理,使用本身的帳戶系統帳號登陸使用。$ nrm add company http://*.*.*.*:4873/
$ nrm use company
$ npm login
複製代碼
網關npm
Github: github.com/yansenleiubuntu