關(guān)于
sinopia 是一個(gè)零配置帶緩存功能的 npm 包管理工具。
sinopia 有以下幾個(gè)優(yōu)勢(shì)值得關(guān)注:
- 不同步拉取 npm 庫,占據(jù)大量硬盤,沒有硬盤被撐爆的問題引矩;
- 安裝配置極其簡(jiǎn)單,不需要數(shù)據(jù)庫;
- 支持配置上游 registry 配置,一次拉取即緩存旺韭;
- 支持 forever 及 pm2 守護(hù)進(jìn)程管理氛谜;
服務(wù)器部署
安裝
> npm install -g sinopia
啟動(dòng)
> sinopia
warn --- config file - C:\Users\jason\AppData\Roaming\sinopia\config.yaml
warn --- http address - http://localhost:4873/
打開 http://localhost:4873/ 如果能正常顯示,說明安裝成功区端。
sinopia 啟動(dòng)時(shí)默認(rèn)會(huì)創(chuàng)建 config.yaml
文件值漫,文件路徑可以看輸出的提示。我們將上面路徑的 config.yaml 拷貝到指定盤符的文件夾下织盼,使用 -c
選項(xiàng)指定配置文件杨何,并執(zhí)行命令:
> sinopia -c D:\sinopia\config.yaml
現(xiàn)在我們就可以在指定目錄下運(yùn)行了,以后上傳的 npm 包也會(huì)放在這個(gè)目錄中沥邻。
配置
config.yaml 是用來配置訪問權(quán)限危虱,代理,文件存儲(chǔ)路徑等所有配置信息的:
#
# This is the default config file. It allows all users to do anything,
# so don't use it on production systems.
#
# Look here for more config file examples:
# https://github.com/rlidwka/sinopia/tree/master/conf
#
# path to a directory with all packages
storage: ./storage //npm包存放的路徑
auth:
htpasswd:
file: ./htpasswd //保存用戶的賬號(hào)密碼等信息
# Maximum amount of users allowed to register, defaults to "+inf".
# You can set this to -1 to disable registration.
max_users: -1 //默認(rèn)為1000唐全,改為-1埃跷,禁止注冊(cè)
# a list of other known repositories we can talk to
uplinks:
npmjs:
url: http://registry.npm.taobao.org/ //默認(rèn)為npm的官網(wǎng),由于國(guó)情邮利,修改 url 讓sinopia使用 淘寶的npm鏡像地址
packages: //配置權(quán)限管理
'@*/*':
# scoped packages
access: $all
publish: $authenticated
'*':
# 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 packages
# (anyone can register by default, remember?)
publish: $authenticated
# if package is not available locally, proxy requests to 'npmjs' registry
proxy: npmjs
# log settings
logs:
- {type: stdout, format: pretty, level: http}
#- {type: file, path: sinopia.log, level: info}
# you can specify listen address (or simply a port)
listen: 0.0.0.0:4873 ////默認(rèn)沒有弥雹,只能在本機(jī)訪問,添加后可以通過外網(wǎng)訪問延届。
客戶端使用
全局安裝 nrm
可以快速修改/切換/增加 npm 鏡像地址:
> npm install -g nrm # 安裝nrm
> nrm add XXXX http://XXXXXX:4873 # 添加私有 npm 鏡像地址
> nrm use XXXX # 使用私有鏡像地址
注意: 不建議使用私有源安裝公網(wǎng) npm 包剪勿,安裝公網(wǎng) npm 包請(qǐng)使用 taobao 源
- 需要安裝私有 npm 包時(shí),請(qǐng)執(zhí)行
nrm use sinopia
切換到私有 npm 源- 安裝公有 npm 包時(shí)方庭,請(qǐng)執(zhí)行
nrm use taobao
切換到淘寶源安裝
nrm 其他命令:
> nrm --help # 查看nrm命令幫助
> nrm list # 列出可用的 npm 鏡像地址
> nrm use taobao # 使用`淘寶npm`鏡像地址
常用 npm 命令
注冊(cè)發(fā)布者
> npm adduser # 按提示輸入用戶名厕吉,密碼,郵箱即可
登陸 npm 源
> npm login # 按提示輸入用戶名二鳄,密碼赴涵,郵箱即可
發(fā)布 npm 包
> cd D:\projects\yourproject # 進(jìn)入項(xiàng)目目錄
> npm publish # 執(zhí)行發(fā)布命令
刪除 npm 包
> npm unpublish <package>@<version> # 例: npm unpublish flagwind@1.0.0
刪除發(fā)布者
> npm <owner> rm <user> <package> # 例: npm admin rm test flagwind
查看模塊所有者
> npm <owner> ls <package> # 例: npm admin ls flagwind
安裝問題
在 Windows 下直接執(zhí)行這個(gè)命令會(huì)遇到一些問題:
1、Python 沒有安裝或版本不對(duì)
gyp ERR! stack Error: Can't find Python executable "python", you can set the PYTHON env variable.
解決方案: node-gyp 依賴 Python 2.7订讼,安裝 Python2.7 并把它添加到環(huán)境變量 PATH 中。
> npm config set python C:\Python27\python.exe
2扇苞、MSBuild 版本不對(duì)
MSBUILD : error MSB4132: The tools version "2.0" is unrecognized. Available too ls versions are "4.0"
解決方案: node-gyp 需要用到 Visual C++ Build Tools欺殿,百度搜索并安裝即可。
3鳖敷、Windows下不支持 fs-ext 和 crypt3
node-gyp 報(bào)編譯 fs-ext 和 crypt3 失敗的錯(cuò)誤脖苏,安裝 sinopia 時(shí)可以忽略,錯(cuò)誤信息如下:
fs-ext.cc(195): error C3861: 'fcntl': identifier not found [C:\Users\clcaza\AppData\Roaming\npm\node_modules\sinopia\node_modules\.0.6.0@fs-ext\build\fs-ext.vcxproj]
crypt3.cc(5): fatal error C1083: Cannot open include file: 'unistd.h': No such file or directory [C:\Users\clcaza\AppData\Roaming\npm\node_modules\sinopia\node\_modules\.0.2.0@crypt3\build\crypt3.vcxproj]
解決方案: sinopia 依賴于 fs-ext
和 crypt3
定踱,但這兩個(gè)包是可選的棍潘,搜索并刪除 sinopia 安裝目錄下所有帶 fs-ext
和 crypt3
字樣的包