verdaccio搭建npm私有倉庫
參考:
搭建NPM私有庫 https://www.jianshu.com/p/1d0e85d14234
用npm發佈包 http://www.cnblogs.com/chengxs/p/7651653.html
安裝verdaccio
# 下載verdacio包
git clone https://github.com/verdaccio/verdaccio#readme
# 安裝
npm install --global verdaccio
# 啓動
verdaccio
# 更改npm配置
npm set registry http://localhost:4873/
# 如果你使用HTTPS, 添加一個適當的CA信息(“null” 的意思從系統獲取CA列表)
npm set ca null
瀏覽 http://localhost:4873/, 這裏將列出已提交的本地包(暫時還沒有)
服務端
運行verdaccio時, 會建立兩個默認的文件(Windows默認路徑 C:\Users\Administrator.config\verdaccio): config.yaml和storge,htpasswd在添加用戶後被創建
- config.yaml 用來配置訪問權限,代理,文件存儲路徑等所有配置信息;
- storge 用來存放NPM包;
- htpasswd 用來保存用戶賬戶、密碼等信息。
封裝發佈本地包
準備一個文件夾(npm_push_test), 裏面包含 入口js(index.js); 最好有一個README.md文件做本地插件包的介紹, 沒有也不影響;
# 初始化要封裝的包
npm init
# 這裏提示輸入:
#- name:填寫個包的名字,默認是這個文件夾的名字(npm有同名的包會報錯);
#- version:包的版本,默認是1.0.0;
#- description:要封裝的包的簡單介紹;
#- entry point:入口文件,默認是index.js,也可以是其它名字;
#- test command:測試命令,直接回車;
#- git repository:這個是git倉庫地址,如果你的包是先放到github上或者其他git倉庫裏,這時候你的文件夾裏面會存在一個隱藏的.git目錄,npm會讀到這個目錄作爲這一項的默認值。如果沒有的話,直接回車繼續;
#- keyword:作爲這個包的索引的關鍵字;
#- author:作者名或賬號;
#- license:許可證, 沒有就直接回車;
之後會生成一個package.json文件;
package.json
{
"name": "local_npm_push_test",
"version": "1.0.0",
"description": "npmjs package test",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [
"npm_push_test"
],
"author": "surliya",
"license": "ISC"
}
發佈包
# 查看npm包鏡像
npm config get registry
# 更改npm包鏡像 (最後的最後再改回來 https://registry.npm.taobao.org)
npm config set registry http://localhost:4873/
# 註冊用戶(在要提交的包文件夾下注冊, 這裏用有用戶名,密碼,郵箱的輸入提示)
npm adduser --registry http://localhost:4873/
# 或者 npm login
# 發佈
npm publish --registry http://localhost:4873/
# 或 npm publish
# 下載
npm install local_npm_push_test
注:
1.發佈新版本時需要改package.json文件裏的版本號;
2.需要覆蓋公共包時, 只需在發佈時更改版本號即可;
3. npm安裝更新出現 npm WARN deprecated [email protected]: If using 2.x branch, please upgrade to at least 2.1.6 to avoid a serious bug with socket data flow and an import issue introduced in 2.1.0 錯誤, 解決方案: 降低版本 npm install [email protected] -g