環境
-
windows10(1803)
-
Nexus Repository Manager OSS 3.x
下載與安裝
-
在官網下載Nexus Repository Manager OSS 3.x, 解壓至任意位置.
-
管理員運行 powershell, 切換到 nexus-3.13.0-01/bin 目錄
$
./nexus.exe /install
進行安裝, 成功后會提示Installed service 'nexus
$
./nexus.exe /run
運行服務, 第一次要耐心等待很久 -
等待啟動完畢后, 進入
http://127.0.0.1:8081
, 點擊右上角Sign In
登陸, 默認賬號: admin 密碼: admin123
添加npm倉庫
以下輸入的Name都是根據自己需求修改
- 點擊在左側菜單
Repositories
, 然后點擊Create repository
按鈕. - 選擇
npm(proxy)
, 輸入 Name: npm-proxy, remote storage 填寫 https://registry.npm.taobao.org 或 https://registry.npmjs.org. 用於將包情求代理到地址地址 - 再次點擊
Create repository
按鈕., 增加 npm(hossted) 輸入 Name: npm-xueyou 用於存放自己的私有包 - 再次點擊
Create repository
按鈕.,增加npm(group) 輸入 Name: npm-all, 下面Member repositories里選擇之前添加的2個移動右邊
配置與驗證npm倉庫
- $
npm config set registry http://localhost:8081/repository/npm-all/
這里的url在倉庫 npm-all 右邊有獲取url - 隨便進入一個目錄, 初始化package,
npm init -y
,npm --loglevel info install grunt
查看是否從自己的倉庫地址拉取包 - 設置權限, Realms 菜單, 將 npm Bearer Token Realm 添加到右邊
- 添加用戶, 然后
npm login –registry=http://192.168.0.102:8081/repository/npm-all/
進行登陸,需要填寫賬號、密碼以及郵箱 - 登陸
npm login --registry=http://192.168.0.102:8081/repository/npm-all/
輸入剛才新建用戶的用戶和密碼和郵箱
發布自己的包
確保要發布的模塊跟目錄有 package.json 文件
- 添加用戶
npm adduser -registry http://192.168.0.102:8081/repository/npm-xueyou/
- 發布包, npm publish –registry http://192.168.0.102:8081/repository/npm-xueyou/
- 修改 package.json 添加
"publishConfig": { "registry": "http://192.168.0.102:8081/repository/npm-xueyou/" }
, 這樣直接npm publish
就發布了
Nexus開啟啟動
nexus/bin
目錄添加到環境變量- 新建
nexus-start.bat
輸入nexus.exe /run
保存 - win + r 輸入
shell:startup
打開C:\Users\tangdekun\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup
目錄, 將文件放進