npm私庫搭建

首先,分享一下,nexus的說明文檔。nexus官網的文檔說明這個連接中的help,打開,而後右側有個能夠打開的連接Repository Management With Nexus - free comprehensive book,打開後,你會發現這裏是不一樣版本的文檔說明,以下圖。node

這裏寫圖片描述

而後能夠選擇你正在試用的Nexus Repository Manager的版本進行查看,咱們使用的是3.0版本的,而後在第10章是專門介紹npm私服的。npm

Nexus Repository Manager中添加npm私服

  • 在Nexus Repository Manager中的設置中點擊create repositories 按鈕。

這裏寫圖片描述

  • 這裏面一共有3中類型的npm倉庫:ide

    • Proxying npm Registries 代理倉庫grunt

      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 託管倉庫ui

      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私服上的代碼this

    • 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 代理倉庫。3d

    • 將標紅的三個地方填寫好。

    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私服中下載的。

這裏寫圖片描述

ok。到這裏結束了,個人淚啊,但願能給你幫助!

相關文章
相關標籤/搜索