Use Nexus3 Repository Manager to build npm PW

Companies generally have their own private servers, plug-ins and other tools used to manage packages, Nexus2 mainly used for unified management maven / gralde warehouse, Nexus3 npm add a plug-in that provides support for npm, in fact, for npm Warehouse Management there is also a tool sinopia, unfortunately, it is already stopped updating.

Download and install

  1. In the official website to download Nexus Repository Manager OSS 3.x , unzip to any location.

  2. Administrators run cmd, switch to the nexus-3.15.2-01 / bin directory

    nexus.exe /install After installation, you will be prompted success Installed service 'nexus

    nexus.exe /run Run the service, the first minor to wait for a long time

  3. After waiting for boot up, enter http://127.0.0.1:8081, click on the upper right corner of Sign Inthe landing, the default account: admin password: admin123

  4. If you prompted could not open SCManagerbecause there is no use to start an administrator cmd

Add npm warehouse

  • Click on the left menu Repositories, you can see a list of warehouse type, as follows:

     

     


    npm (group) represents a packet, npm (hosted) indicates native private, npm (proxy) indicates a remote agent.
    If the registry is configured to group (including hosted and proxy), will first take from hosted, if not taken from the proxy and cache, the next time will be taken from the cache.

     

  • Click Create repository button to create a warehouse

  • Select npm(proxy), enter Name: npm-proxy, remote storage fill https://registry.npm.taobao.org or https://registry.npmjs.org for packet case the address request to the address proxy.

     

     

  • 再次点击Create repository按钮., 增加 npm(hosted) 输入 Name: npm-hosted 用于存放自己的私有包


     

     

  • 再次点击Create repository按钮.,增加npm(group) 输入 Name: npm-all, 下面Member repositories里选择之前添加的2个移动右边


     

     

配置与验证npm仓库

  • 查看并设置nodejs的默认仓库地址
npm config get registry  #http://registry.cnpmjs.org/
npm config set registry http://localhost:8081/repository/npm-group/
  • 设置完成后,可以找到当前用户目录下的.npmrc文件,内容如下:


     

     

  • 随便进入一个目录, 初始化package, npm init -y, npm --loglevel info install jquery 查看是否从自己的仓库地址拉取包
npm init -y
npm --loglevel info install jquery
#查看本地包的缓存地址(和私服无关)命令
npm config get cache
 

 


从上图中可以看到,fetch地址即为私服地址。
查看刚搭建的私服里的内容为空, 在安装了依赖包后,就会有一些被缓存了,下次请求就不会走外网了。


 

 

发布包到私服

npm发布包是需要先登录的,默认是登录到npm官方服务器,若registry已更改为其它地址则可能登录失败,而这里我们只是想把包发布到自己私有的服务器上。

  1. 添加权限认证
    设置权限, Realms 菜单, 将 npm Bearer Token Realm 添加到右边
  2. 创建nx-deploy角色
    给角色赋于一个nx-repository-view-*-*-*权限
     

     

  3. 创建deployer 用户,密码也为 deployer,同时设定角色为nx-deploy


     

     

  4. 客户端的.npmrc配置
registry=http://127.0.0.1:8081/repository/npm-group/
[email protected]
always-auth=true
_auth="ZGVwbG95ZXI6ZGVwbG95ZXI=" 

_auth是 username:password 的base64值,这样设置的好处是publish时就不用login了。

  1. 发布控件到npm私服中
    在package.json 配置
"publishConfig" : {
    "registry" : "http://localhost:8081/repository/npm-hosted/"
  }

在包根目录执行npm publish即可。
如下:

 

 


Note: Publishing is npm-hosted, not npm-group.
If we are not configured in package.json, can also be specified on the command line, as follows:

 

$ npm publish --registry=http://localhost:8081/repository/npm-hosted/
+ vue-hslider@1.0.0 

Nexus3 migrate data backup

The network environment, need a lot of packets transferred from the external network, the external network can be associated package mounting test is successful, then the buffered packets can be copied directly to the network.

Linux

  • Warehouse migration
    components are stored in a warehouse Nexus sonatype-work directory, the directory location specified by the nexus / conf / nexus.properties profile.
    Warehouse migration requires two procedures: Backup and Restore

  • Backup warehouse
    will sonatype-work overall backup folder you can, you can choose to back up only the two most important folder index (indexer) and warehouse (storage)

  • Restore warehouse
    will be a good backup sonatype-work files are copied to the new server. Then modify the nexus / conf / nexus.properties configuration file, re-designated directory in the repository.

Windows

  • Warehouse Migration
    member are stored in the warehouse Nexus sonatype-work directory, the directory location specified by the bin / nexus.vmoptions profile (Dkaraf.data).
    Warehouse migration requires two procedures: Backup and Restore

  • Backup warehouse
    will sonatype-work overall backup folder you can, you can choose to back up only the two most important folder index (indexer) and warehouse (storage)

  • Restore warehouse
    will be a good backup sonatype-work files are copied to the new server. Then modify the bin / nexus.vmoptions configuration file, re-designated directory in the repository.




Original: https: //www.jianshu.com/p/1674a6bc1c12

Guess you like

Origin www.cnblogs.com/cangqinglang/p/11284883.html