基于verdaccio的npm私有仓库搭建和使用总结

33次阅读

共计 2121 个字符,预计需要花费 6 分钟才能阅读完成。

资源

官方:https://github.com/verdaccio/…

参考:https://blog.csdn.net/yyzzhc9…

参考:https://www.jianshu.com/p/16b…

参考:https://www.jianshu.com/p/1d0…

原来用 sinopia 搭建的私服,但 sinopia 两年年停止维护了,现在改为 verdaccio。使用 verdaccio 也超级简单,只需几分钟就可以搭建一个私服,适合公司内部不对外的包的安装
一:安装和配置
A. 安装
$ yarn global add verdaccio
yarn global v1.12.3
[1/4] Resolving packages…
[2/4] Fetching packages…
[3/4] Linking dependencies…
[4/4] Building fresh packages…
success Installed “verdaccio@3.10.1” with binaries:
– verdaccio
Done in 52.10s.
安装到了 C:\Users\Administrator\AppData\Local\Yarn\bin[我的是 win10]
B. 测试
随便建一个空目录测试,我当前工作目录是 F:\youshengyouse\del3
$ verdaccio
warn — config file – C:\Users\Administrator\.config\verdaccio\config.yaml
warn — Plugin successfully loaded: htpasswd
warn — Plugin successfully loaded: audit
warn — http address – http://localhost:4873/ – verdaccio/3.10.1
在浏览器输入 http://localhost:4873/,结果如下
二:添加用户
另开一个命令行窗口,原来的 verdaccio 仍在运行
$ npm adduser –registry http://localhost:4873
Username: abcd
Password: qwer
Email: (this IS public) a@163.com
Logged in as abcd on http://localhost:4873/.
三:发布私包
当前工作目录:要发布哪个包,当前目录切换到包根目录下
$ npm publish –registry http://localhost:4873

> gatsby2-cli@1.0.0 prepare .
> cross-env NODE_ENV=production npm run build

> gatsby2-cli@1.0.0 build F:\youshengyouse\frontend\packages\gatsby\packages\gatsby2-cli
> babel src –out-dir lib –ignore **/__tests__

Successfully compiled 6 files with Babel.
npm notice
npm notice package: gatsby2-cli@1.0.0
npm notice === Tarball Contents ===
npm notice 1.8kB package.json
npm notice 7.4kB CHANGELOG.md
npm notice 3.3kB README.md
npm notice 9.4kB lib/create-cli.js
npm notice 2.7kB lib/index.js
npm notice 4.7kB lib/init-starter.js
npm notice 2.0kB lib/reporter/errors.js
npm notice 3.1kB lib/reporter/index.js
npm notice 4.0kB lib/reporter/prepare-stack-trace.js
npm notice === Tarball Details ===
npm notice name: gatsby2-cli
npm notice version: 1.0.0
npm notice package size: 11.0 kB
npm notice unpacked size: 38.3 kB
npm notice shasum: 64c9c47b81610731e559bc33f86aa02f87155656
npm notice integrity: sha512-vhroNpnWCwivE[…]8hAg+z6SPOeyw==
npm notice total files: 9
npm notice
+ gatsby2-cli@1.0.0
现在刷新 http://localhost:4873/#/ 就可以看到刚才发布的包问题:本地安装的包放在哪里了呢?
四:安装包
npm set registry http://localhost:4873/
$ npm init # 如果没有 package.json 文件得先建
$ yarn add gatsby2-cli
发现 gatsby2-cli 是在本地的,其余的依赖还是从 npmjs.com 仓库中安装的

正文完
 0