號外號外,我家已建立了快遞點,不用再跑鎮上了
前序:
- 此搭建整合了網上以及官網的教程。
- 選擇自己搭建服務器,一個爲公司項目的考慮,公共庫有公共庫的好處,私有庫所能體現的爲可控,穩定,安全,當然也跟你選擇的庫的工具有關。
- 選擇verdaccio,一個是它常更新,一個是基於網上大多數教程的sinopia延伸的,一個就是docker的支持,它有docker的鏡像,這倒是省了很多東西,最近還是喜歡弄docker,當然還有其他工具可選,請自行查閱,這裏僅僅就verdaccio搭建。
- 此處分2個版本,一個是默認版,一個是自定義版(廢話最多的版)
前提:
一:步驟:默認版
npm install --global verdaccio
verdaccio --listen 端口號
二:步驟:自定義版
1. 安裝 Verdaccio
npm install --global verdaccio
npm install --global verdaccio --registry 源地址
2. 設置 Verdaccio的倉儲路徑(本人不習慣什麼都裝到C盤,若是沒這種習慣的,請跳過這個步驟)
1.0 選擇自己喜歡的盤,創建文件(默認是Verdaccio,當然你喜歡爲主,就像我喜歡這樣折騰)
2.0 將在c盤存在的配置文件完封不動地剪切到新文件,一般新裝纔有,其實我更希望它自安裝的命令能改爲自己定義,那樣就不用這麼麻煩,當然源碼都有了,還是可以改,但是我還是懶,故原始做法,windos的默認路徑爲
C:\Users\你的登錄用戶名稱\AppData\Roaming\verdaccio
2.1 修改後的目錄結構
- Verdaccio
- storage
- config.yaml
- htpasswd(一開始這個不存在,啓動後由配置自動生成)
3. 修改配置文件,當然你也可以直接把我這份拿去用,前提是符合安裝版本以及你的喜好官網配置栗子
# 設置你存儲的包的位置,當前表示和配置文件同目錄下的storage
storage: ./storage
# 插件位置
plugins: ./plugins
web:
title: Verdaccio
# comment out to disable gravatar support
# gravatar: false
# by default packages are ordercer ascendant (asc|desc)
# sort_packages: asc
auth:
htpasswd:
file: ./htpasswd
# Maximum amount of users allowed to register, defaults to "+inf".
# You can set this to -1 to disable registration.
# max_users: 1000
# 設置源地址
uplinks:
npmjs:
url: https://registry.npmjs.org/
taobao:
url: http://registry.npm.taobao.org/
packages:
'@*/*':
# scoped packages
access: $all
publish: $authenticated
unpublish: $authenticated
proxy: taobao
# 設置權限,可以限制某些賬號瀏覽和發佈包
'**':
# allow all users (including non-authenticated users) to read and
# publish all packages
#
# you can specify usernames/groupnames (depending on your auth plugin)
# and three keywords: "$all", "$anonymous", "$authenticated"
access: $all
# allow all known users to publish/publish packages
# (anyone can register by default, remember?)
publish: $authenticated
unpublish: $authenticated
# 當你的請求的包不在本地庫時,會請求下面的代理獲取,這裏將npmjs改成了淘寶庫,當然你也可以改成其他的
proxy: taobao
# You can specify HTTP/1.1 server keep alive timeout in seconds for incoming connections.
# A value of 0 makes the http server behave similarly to Node.js versions prior to 8.0.0, which did not have a keep-alive timeout.
# WORKAROUND: Through given configuration you can workaround following issue https://github.com/verdaccio/verdaccio/issues/301. Set to 0 in case 60 is not enough.
server:
keepAliveTimeout: 60
middlewares:
audit:
enabled: true
# 日誌 設置
logs:
- { type: stdout, format: pretty, level: http }
#- {type: file, path: verdaccio.log, level: info}
#experiments:
# # support for npm token command
# token: false
#自定義監聽端口,減少命令啓動配置
listen: 0.0.0.0:8081
4.CMD窗口啓動 Verdaccio 服務(前提爲環境變量存在npm的安裝目錄,否則就得切換到npm的安裝目錄才能使用這些命令,畢竟這些插件的bat就在這裏,還有就是啓動這個不要關閉命令窗口,關閉等於退出,故後面會有進程守護工具或者將改服務做成windos服務,那樣就可以自啓動和服務故障會自動重啓服務)
# 默認位置,啓動
verdaccio
#配置文件沒寫listen或者想自己改端口啓動的都可以選擇此命令
verdaccio --listen 端口號 --config config.yaml的位置
#例:
verdaccio --listen 1111 --config C:\verdaccio\config.yaml
#配置文件已寫listen並自定義配置文件的選擇此命令
verdaccio --config config.yaml的位置
#例:
verdaccio --config C:\verdaccio\config.yaml
5. 至此搭建完畢,啓動的地址爲 http://localhost:你設置的端口號/ 當然要是你部署在雲服務器或者已經將本地映射到固有域名,就可以域名:你設置的端口號訪問了,注意:你得開放該端口,否則外面還是沒法訪問到,後面會有專門篇節說明怎麼使用,欲知後事如何,請看後回分解。