2023年了, 简单搭建一个npm私服

2,267 阅读1分钟

开发npm包时,有时我们想测试一下发布后的包能不能用,或者查看发布的包的内容,又不想总是上传到npm官方平台,或者只给内部使用,这个时候不妨试一下建立一个npm私服

1、安装verdaccio

npm install -g verdaccio

2、启动verdaccio服务

verdaccio

默认端口是4873 image.png

3、访问http://localhost:4873/

image.png

4、按照页面显示步骤操作

1、create user添加用户

npm adduser --registry http://localhost:4873/

image.png 2、publish发布包

npm publish --registry http://localhost:4873/

image.png 3、refresh this page 刷新页面 image.png

image.png

5、查看发布的包的内容

有两种方式 1、npm 指定源安装

npm --registry http://localhost:4873 install test001-utils

image.png

2、直接访问http://localhost:4873/ 下载

image.png

6、改变发布的包的内容

我们可以通过改变package.json里的files字段数组来改变发布的包的包含内容, 如果只想包含dist目录就只写dist

"files": [
    "dist"
]

7、怎么让内网其他人访问

默认只能本机localhost访问,通过改变配置文件使内网其他同时访问,启动服务后第一行写着配置文件的位置

image.png 增加一行,重新启动,就可以通过内网ip访问了

listen: 0.0.0.0:4873

image.png