windows下使用verdaccio构建npm私服环境

一.背景

npm太慢了,每次jenkins自动构建等太久,我虽然是后端coder,也看不惯。本文目的只是说明怎么搭建npm私服,我现在只想构建快一点。所以,暂时没有考虑多个开发者将自定义组件上传到私库并共享的问题,以后有时间再说吧。

二.npm环境准备

详见我之前的文章windows系统下安装nodejs-CSDN博客

三.安装verdaccio

输入命令安装

npm install -g verdaccio --unsafe-perm

安装正常情况还是很快,大概30秒以内,结果如下

Microsoft Windows [版本 10.0.17763.107]
(c) 2018 Microsoft Corporation。保留所有权利。

C:\Users\Administrator>npm install -g verdaccio --unsafe-perm

added 262 packages in 34s

38 packages are looking for funding
  run `npm fund` for details
npm notice
npm notice New minor version of npm available! 10.2.4 -> 10.4.0
npm notice Changelog: https://github.com/npm/cli/releases/tag/v10.4.0
npm notice Run npm install -g npm@10.4.0 to update!
npm notice

C:\Users\Administrator>

四.启动verdaccio

在刚刚的cmd中,继续输入verdaccio,启动大概10秒左右。结果如下

C:\Users\Administrator>verdaccio
(node:2296) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
(Use `node --trace-deprecation ...` to show where the warning was created)
 info --- config file  - C:\Users\Administrator\AppData\Roaming\verdaccio\config.yaml
 info --- the "crypt" algorithm is deprecated consider switch to "bcrypt" in the configuration file. Read the documentation for additional details
 info --- using htpasswd file: C:\Users\Administrator\AppData\Roaming\verdaccio\htpasswd
 info --- plugin successfully loaded: verdaccio-htpasswd
 info --- plugin successfully loaded: verdaccio-audit
 warn --- http address - http://localhost:4873/ - verdaccio/5.29.0

五.修改访问地址

按照上面的提示,在浏览器输入http://localhost:4873/ 可以看到如下界面,说明启动是成功的。

但是,当我们用ip访问就不行了。

这是因为,监听的是localhost,要修改监听为0.0.0.0 。因为安装好了后别人要使用啊,肯定不会输入localhost来连接我们的私服,所以要修改,是的ip也可以访问。

根据上一步中启动后的提示,我们知道配置文件的位置如下

info --- config file - C:\Users\Administrator\AppData\Roaming\verdaccio\config.yaml

找到文件,在文件中搜索listen,找到对应的注释这一段后面,按照注释给你的规范,配置输入 listen: - 0.0.0.:4873

(在注释的位置后面做配置是良好的习惯)

# https://verdaccio.org/docs/configuration#listen-port
# listen:
# - localhost:4873            # default value
# - http://localhost:4873     # same thing
# - 0.0.0.0:4873              # listen on all addresses (INADDR_ANY)
# - https://example.org:4873  # if you want to use https
# - "[::1]:4873"                # ipv6
# - unix:/tmp/verdaccio.sock    # unix socket
listen:
- 0.0.0.0:4873

修改后,重启一下(重启不应该我还要记录吧。。。在刚刚的cmd中,ctrl+c,按小键盘的上或者重新输入verdaccio,敲回车),就能ip访问了。

六.修改仓库位置

想指定verdaccio组件存储位置,还是在上一步的文件中,找到storage,有默认的配置。可以不修改哈,默认就可以。

七.指定代理仓库

这个是解决我构建慢的最关键步骤。我们安装verdaccio后,我们的仓库中空空的,如果别人要使用我们就下载不到东西,所以,我们还要指定代理仓库。因为npm在国内用起来很慢,所以我们指定上级为大厂的地址。阿里的也勉强,我更喜欢华为的。还在在之前的config.yaml文件中,找到uplinks。输入配置如下:

# https://verdaccio.org/docs/configuration#uplinks
# a list of other known repositories we can talk to
uplinks:
  npmjs:
#    url: https://registry.npmjs.org/
    url: https://mirrors.huaweicloud.com/repository/npm/

我是先注释了原来的上级代理仓库配置(行前面加#就是注释,你不会不知道吧?),然后复制了一行写上了华为的代理。

相关推荐
渔夫阿布13 小时前
在MAC上面通过HomeBrew安装node和npm@指定版本
前端·macos·npm
雲小妖1 天前
PowerShell 执行策略:fnm管理软件安装nodejs无法运行npm,错误信息:about_Execution_Policies
前端·npm·node.js
qq_530245191 天前
nvm下载node版本npm下载失败
前端·npm·node.js·nvm
Winson℡1 天前
在使用 npm link 进行本地 npm 包调试时,是否需要删除项目中已安装的依赖包取决于你的调试场景和依赖管理方式
前端·npm·node.js
AlgorithmAce2 天前
解决npm/yarn等包管理工具在vscode中使用出现系统禁止运行脚本的情况
前端·npm·node.js
超级无敌谢大脚2 天前
前端包管理工具进化论:npm vs yarn vs pnpm 深度对比
前端·npm·node.js
Merlyn103 天前
npm : 无法加载文件 E:\ProgramFiles\Nodejs\npm.ps1,因为在此系统上禁止运行脚本。
前端·npm·node.js
一个打工仔的笔记3 天前
npm i 失败权限问题
前端·npm·node.js
heroboyluck3 天前
rust 前端npm依赖工具rsup升级日志
前端·rust·npm
HugeYLH4 天前
解决npm问题:错误的代理设置
前端·npm·node.js