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 [email protected] 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

你可能感兴趣的:(前端,工器具,npm,私服,使用,verdaccio,构建)