首先,分享一下,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 代理倉庫。
- 將標紅的三個地方填寫好。
- 同樣是填寫標紅的地方。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。到這里結束了,我的淚啊,希望能給你幫助!