使用 Verdaccio搭建私有npm库

官网:
https://verdaccio.org/docs/installation
参考:
https://www.jianshu.com/p/bb4e90b2f7b7
https://www.jianshu.com/p/9a9ed7eaf655

选用 Verdaccio,因为免费。

安装

Using npm
npm install -g verdaccio

or using yarn
yarn global add verdaccio

or using pnpm
pnpm install -g verdaccio

运行

verdaccio

image

在浏览器中输入 http://localhost:4873/ ,出现如下界面。
image

创建 npm 包

输入 npm init,根据提示输入信息。
我配置的包名是 npm-test
一般来说默认的入口是index.js。新建一个入口文件并编写代码。

切换 npm 源->注册账号->发布包

全局安装 nrm, 用于快速地在 npm 源间切换

npm install -g nrm
1.添加私有源
$ nrm add [自己取一个私有源名称] http://localhost:4873/

2.切换源
$ nrm use [私有源名称]
或
npm set registry http://localhost:4873/

3.注册用户
$ npm adduser

登陆成功之后,在刚才编写的项目终端输入npm publish ,回车。
查看 http://localhost:4873/ ,可以看到刚才发布的包。

更新包

修改代码,记得更新package.json中的版本号,然后发布。
查看 http://localhost:4873/ ,可以看到刚才发布的包。
image

posted @ 2021-08-06 12:16  bcj7wi3kd5h1wd6  阅读(53)  评论(0编辑  收藏  举报