本文介绍: vue工程构建时,使用我们verdaccio搭建的私服,构建速度明显提升。

一.verdaccio的准备

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

二.用nrm实现npm源管理

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

1.安装nrm

输入npm install -g nrm

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

C:UsersDell>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:UsersDellAppDataLocalnpm-cache_logs2024-02-02T02_05_58_445Z-debug-0.log

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

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

安装成功了,如下:

C:UsersDell>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:UsersDell>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:UsersDell>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:UsersDell>nrm use localnpm
 SUCCESS  The registry has been changed to 'localnpm'.

5.通过nrm查看默认npm源

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

C:UsersDellqiankunbag-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:UsersDellqiankunbag-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

原文地址:https://blog.csdn.net/qq_37372909/article/details/135987678

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。

如若转载,请注明出处:http://www.7code.cn/show_67509.html

如若内容造成侵权/违法违规/事实不符,请联系代码007邮箱:suwngjj01@126.com进行投诉反馈,一经查实,立即删除!

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注