npm 替换淘宝镜像

1.得到原本的镜像地址

npm get registry 

> https://registry.npmjs.org/

设成淘宝的

npm config set registry http://registry.npm.taobao.org/

cnpm config set registry http://registry.npm.taobao.org/

  

2.换成原来的

npm config set registry https://registry.npmjs.org/

cnpm config set registry https://registry.npmjs.org/

npm私库搭建

首先,分享一下,nexus的说明文档。nexus官网的文档说明这个链接中的help,打开,然后右侧有个可以打开的链接Repository Management With Nexus - free comprehensive book,打开后,你会发现这里是不同版本的文档说明,如下图。

这里写图片描述

然后可以选择你正在试用的Nexus Repository Manager的版本进行查看,我们使用的是3.0版本的,然后在第10章是专门介绍npm私服的。

Nexus Repository Manager中添加npm私服

  • 在Nexus Repository Manager中的设置中点击create repositories 按钮。

这里写图片描述

  • 这里面一共有3中类型的npm仓库:

    • Proxying npm Registries 代理仓库

      To reduce duplicate downloads and improve download speeds for your developers and CI servers, you should proxy the registry hosted at https://registry.npmjs.org. By default npm accesses this registry directly. You can also proxy any other registries you require. 
      大致的意思就是说,可以访问远程仓库的一些代码,比如angular的代码

    • Private npm Registries 托管仓库

      A private npm registry can be used to upload your own packages as well as third-party packages. You can create a private npm registry by setting up a hosted repository with the npm format in the repository manager. It is good practice to create two separate hosted repositories for these purposes. 
      大致的意思是说,这是你的私服,可以放你要放到自己的npm私服上的代码

    • Grouping npm Registries 存储库组(不知道这样翻译怎么样)

      A repository group is the recommended way to expose all your npm registries repositories from the repository manager to your users, without needing any further client side configuration. A repository group allows you to expose the aggregated content of multiple proxy and hosted repositories with one URL to npm and other tools. 
      这是一个综合性的库组,可以将请两个综合起来,下面有详细的介绍。

  • 创建Proxying npm Registries 代理仓库。

    • 将标红的三个地方填写好。

    Proxying npm Registries创建时需要填写的地方

    • 同样是填写标红的地方。name and blob store即可。

       创建Proxying npm Registries hosted本地仓库。

  • 创建 Grouping npm Registries 综合仓库

    • 这是将强两个单独的仓库合并起来。

    这里写图片描述

  • 到这里,已经完成了50%了。好了,我们来看一下,创建好的npm私服。

    • 这里写图片描述
  • 接下来,我们需要配置一下npm 

  • win + R 打开window 命令行,设置 离线库地址:  npm config set registry http://localhost:8081/repository/npm-all/  (这个就是合并起来的那个路径地址,进到自己group里面查看这个地址)
  • npm config ls  查看本地地址是否已经替换成了离线库地址

到这里,npm的私服创建完毕,接下来,我们要验证一下了。

验证npm私服是否创建成功

随便在一个目录下,进入cmd,然后执行npm –loglevel info install grunt,看看是够能够下载成功,只是下载成功是不够,还要看下,是不是从你的npm私服中进行下载的。

下图是下载成功,在对应目录下会多一个文件node_modules,注意,你需要删除,因为是测试的

这里写图片描述

还需要验证是否是从npm私服中下载的。

这里写图片描述

摘自: https://www.cnblogs.com/fang888/category/1287408.html

原文地址:https://www.cnblogs.com/fengjian2016/p/14212033.html