windows下利用verdaccio私服让npm构建速度上来

一.verdaccio的准备

上一篇文章,我写了的,看这里。windows下使用verdaccio构建npm私服环境-CSDN博客

二.用nrm实现npm源管理

虽然英语不好,我猜这个工具的缩写的意思是npm resource manage,哈哈。

1.安装nrm

输入npm install -g nrm

结果,我遇到了问题,如下:

C:\Users\Dell>npm install -g nrm
npm ERR! code CERT_HAS_EXPIRED
npm ERR! errno CERT_HAS_EXPIRED
npm ERR! request to https://registry.npm.taobao.org/nrm failed, reason: certificate has expired

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Dell\AppData\Local\npm-cache\_logs\2024-02-02T02_05_58_445Z-debug-0.log

我之前好像设置了npm的源为淘宝的,现在提示过期了。估计像之前的maven代理地址,需要每个人登录去获取自己的地址。换华为地址吧

npm install -g nrm --registry=https://mirrors.huaweicloud.com/repository/npm

安装成功了,如下:

C:\Users\Dell>npm install -g nrm --registry=https://mirrors.huaweicloud.com/repository/npm

added 17 packages in 13s

4 packages are looking for funding
  run `npm fund` for details
npm notice
npm notice New major version of npm available! 8.15.0 -> 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

2.查看当前npm源地址

输入 nrm ls,结果如下:

C:\Users\Dell>nrm ls
  npm ---------- https://registry.npmjs.org/
  yarn --------- https://registry.yarnpkg.com/
  tencent ------ https://mirrors.cloud.tencent.com/npm/
  cnpm --------- https://r.cnpmjs.org/
  taobao ------- https://registry.npmmirror.com/
  npmMirror ---- https://skimdb.npmjs.com/registry/

3.添加npm私库

nrm add localnpm http://10.1.230.123:4873

然后再看看,我们的私库地址就在里面了。

C:\Users\Dell>nrm ls
  npm ---------- https://registry.npmjs.org/
  yarn --------- https://registry.yarnpkg.com/
  tencent ------ https://mirrors.cloud.tencent.com/npm/
  cnpm --------- https://r.cnpmjs.org/
  taobao ------- https://registry.npmmirror.com/
  npmMirror ---- https://skimdb.npmjs.com/registry/
  localnpm ----- http://10.1.230.123:4873/

4.指定使用私库

输入nrm use localnpm,结果是指定成功,如下:

C:\Users\Dell>nrm use localnpm
 SUCCESS  The registry has been changed to 'localnpm'.

5.通过nrm查看默认npm源

再输入nrm ls。我们的localnpm前面多了一个"*",代表它是默认的源了。

C:\Users\Dell\qiankunbag-vue>nrm ls
  npm ---------- https://registry.npmjs.org/
  yarn --------- https://registry.yarnpkg.com/
  tencent ------ https://mirrors.cloud.tencent.com/npm/
  cnpm --------- https://r.cnpmjs.org/
  taobao ------- https://registry.npmmirror.com/
  npmMirror ---- https://skimdb.npmjs.com/registry/
* localnpm ----- http://10.1.230.123:4873/

三.构建测试

先拿之前的前端代码,构建试试

C:\Users\Dell\qiankunbag-vue>npm install
*********中间省略了哦
added 2012 packages in 45s

45秒,虽然还是有点慢,但我可以接受了。

通过私库上的日志输出,我们也可以看到,我本次构建是访问了私服的。虽然有的请求有问题,暂时不去深究哈,构建成功就行!(我本机的ip就是10.2.20.73。你不会不知道ipconfig查看ip吧?)

 http --- 200, req: 'GET https://mirrors.huaweicloud.com/repository/npm/@soda%2Ffriendly-errors-webpack-plugin' (streaming)
 http --- 200, req: 'GET https://mirrors.huaweicloud.com/repository/npm/@soda%2Ffriendly-errors-webpack-plugin', bytes: 0/16696
 http <-- 304, user: null(10.2.20.73), req: 'GET /@soda%2ffriendly-errors-webpack-plugin', bytes: 0/0
 info <-- 10.2.20.73 requested 'POST /-/npm/v1/security/advisories/bulk'
 http <-- 200, user: null(10.2.20.73), req: 'POST /-/npm/v1/security/advisories/bulk', bytes: 11863/0
 warn --- could not fetch audit: FetchError: request to https://registry.npmjs.org/-/npm/v1/security/advisories/bulk failed, reason:
 http <-- 500, user: null(10.2.20.73), req: 'POST /-/npm/v1/security/advisories/bulk', bytes: 11863/0
 info <-- 10.2.20.73 requested 'POST /-/npm/v1/security/audits/quick'
 http <-- 200, user: null(10.2.20.73), req: 'POST /-/npm/v1/security/audits/quick', bytes: 667/0
 warn --- could not fetch audit: FetchError: request to https://registry.npmjs.org/-/npm/v1/security/audits/quick failed, reason:
 http <-- 500, user: null(10.2.20.73), req: 'POST /-/npm/v1/security/audits/quick', bytes: 667/0
相关推荐
GDAL3 小时前
npm入门教程1:npm简介
前端·npm·node.js
Amd79410 小时前
Nuxt.js 应用中的 build:error 事件钩子详解
日志·nuxt·错误·通知·构建·处理·钩子
乐迁~14 小时前
关于npm源的切换及相关操作
npm
GDAL1 天前
npm入门教程13:npm workspace功能
前端·npm·node.js
wumu_Love1 天前
npm 和 node 总结
前端·npm·node.js
J不A秃V头A1 天前
报错:npm : 无法加载文件 C:\Program Files\nodejs\npm.ps1,因为在此系统上禁止运行脚本。
前端·npm·node.js
GDAL1 天前
npm入门教程14:npm依赖管理
前端·npm·node.js
Amd7943 天前
Nuxt.js 应用中的 nitro:build:before 事件钩子详解
自定义·生命周期·配置·优化·nuxt·构建·钩子
GDAL4 天前
npm入门教程8:缓存管理
前端·缓存·npm
GDAL4 天前
npm入门教程18:npm发布npm包
前端·npm·node.js