前言
公司内部会有一些私有组件,往往会涉及到公司业务等等私密因素,所以肯定是不能开源发布到npm。
那么就有了私有npm仓库的概念。
搭建方案有很多,作为前端,还是推荐使用 verdaccio
使用
基础
安装命令很常规,一条足以
npm install --global verdaccio
然后直接运行即可
> verdaccio
warn --- config file - C:\Users\Dell\AppData\Roaming\verdaccio\config.yaml
warn --- Verdaccio started
warn --- Plugin successfully loaded: verdaccio-htpasswd
warn --- Plugin successfully loaded: verdaccio-audit
warn --- http address - http://localhost:4873/ - verdaccio/4.6.2
使用的时候需要先添加用户
npm login --registry http://localhost:4873
然后就能直接提交私有仓库代码了
npm publish --registry http://localhost:4873
进阶
上面只是常规的配置,如果真正的要使用,我个人建议配合nrm使用
npm i -g nrm // 安装nrm
nrm add my_name http://localhost:4873/ //添加nrm源
> nrm ls //查看源
npm -------- https://registry.npmjs.org/
yarn ------- https://registry.yarnpkg.com/
cnpm ------- http://r.cnpmjs.org/
taobao ----- https://registry.npm.taobao.org/
nj --------- https://registry.nodejitsu.com/
npmMirror -- https://skimdb.npmjs.com/registry/
edunpm ----- http://registry.enpmjs.org/
* my_name ------- http://localhost:4873/
> nrm use my_name //切换源
Registry has been set to: http://localhost:4873/
之后就可以像往常一样正常使用了
说明
公司内部使用的话照着上一步即可
- 切换仓库
- npm i
如果需要推送依赖,使用 login 注册,然后 publish 即可
更多
verdaccio 默认使用的npm源,可以通过修改 config.yaml切换到第三方源加快速度
uplinks:
npmjs:
url: https://registry.npm.taobao.org