sinopia 有如下几个优点值得关注:php
> npm install -g sinopia
> sinopia warn --- config file - C:\Users\jason\AppData\Roaming\sinopia\config.yaml warn --- http address - http://localhost:4873/
打开 http://localhost:4873/ 若是能正常显示,说明安装成功。node
sinopia 启动时默认会建立 config.yaml
文件,文件路径能够看输出的提示。咱们将上面路径的 config.yaml 拷贝到指定盘符的文件夹下,使用 -c
选项指定配置文件,并执行命令:python
> sinopia -c D:\sinopia\config.yaml
如今咱们就能够在指定目录下运行了,之后上传的 npm 包也会放在这个目录中。git
config.yaml 是用来配置访问权限,代理,文件存储路径等全部配置信息的:github
# # 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 //保存用户的帐号密码等信息 # Maximum amount of users allowed to register, defaults to "+inf". # You can set this to -1 to disable registration. max_users: -1 //默认为1000,改成-1,禁止注册 # a list of other known repositories we can talk to uplinks: npmjs: url: http://registry.npm.taobao.org/ //默认为npm的官网,因为国情,修改 url 让sinopia使用 淘宝的npm镜像地址 packages: //配置权限管理 '@*/*': # 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 ////默认没有,只能在本机访问,添加后能够经过外网访问。
全局安装 nrm
能够快速修改/切换/增长 npm 镜像地址:数据库
> npm install -g nrm # 安装nrm > nrm add XXXX http://XXXXXX:4873 # 添加私有 npm 镜像地址 > nrm use XXXX # 使用私有镜像地址
注意: 不建议使用私有源安装公网 npm 包,安装公网 npm 包请使用 taobao 源npm
- 须要安装私有 npm 包时,请执行
nrm use sinopia
切换到私有 npm 源- 安装公有 npm 包时,请执行
nrm use taobao
切换到淘宝源安装
nrm 其余命令:缓存
> nrm --help # 查看nrm命令帮助 > nrm list # 列出可用的 npm 镜像地址 > nrm use taobao # 使用`淘宝npm`镜像地址
注册发布者ruby
> npm adduser # 按提示输入用户名,密码,邮箱便可
登录 npm 源bash
> npm login # 按提示输入用户名,密码,邮箱便可
发布 npm 包
> cd D:\projects\yourproject # 进入项目目录 > npm publish # 执行发布命令
删除 npm 包
> npm unpublish <package>@<version> # 例: npm unpublish flagwind@1.0.0
删除发布者
> npm <owner> rm <user> <package> # 例: npm admin rm test flagwind
查看模块全部者
> npm <owner> ls <package> # 例: npm admin ls flagwind
在 Windows 下直接执行这个命令会遇到一些问题:
一、Python 没有安装或版本不对
gyp ERR! stack Error: Can't find Python executable "python", you can set the PYTHON env variable.
解决方案: node-gyp 依赖 Python 2.7,安装 Python2.7 并把它添加到环境变量 PATH 中。
> npm config set python C:\Python27\python.exe
二、MSBuild 版本不对
MSBUILD : error MSB4132: The tools version "2.0" is unrecognized. Available too ls versions are "4.0"
解决方案: node-gyp 须要用到 Visual C++ Build Tools,百度搜索并安装便可。
三、Windows下不支持 fs-ext 和 crypt3
node-gyp 报编译 fs-ext 和 crypt3 失败的错误,安装 sinopia 时能够忽略,错误信息以下:
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
,但这两个包是可选的,搜索并删除 sinopia 安装目录下全部带 fs-ext
和 crypt3
字样的包
来源:https://www.jianshu.com/p/c2a569be60a9