大佬教程收集整理的这篇文章主要介绍了windows 环境部署私有 npm 源,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
sinopia 有以下几个优势值得关注:@H_696_24@
> npm install -g sinopia
> sinopia warn --- config file - C:\Users\jason\ApPDAta\roaR_973_11845@ing\sinopia\config.yaml warn --- http address - http://localhost:4873/
打开 http://localhost:4873/ 如果能正常显示,说明安装成功。@H_696_24@
@H_696_24@@H_696_24@
@H_674_2@
@H_674_2@
sinopia 启动时默认会创建 config.yaml
文件,文件路径可以看输出的提示。我们将上面路径的 config.yaml 拷贝到指定盘符的文件夹下,使用 -c
选项指定配置文件,并执行命令:@H_696_24@
> sinopia -c D:\sinopia\config.yaml
现在我们就可以在指定目录下运行了,以后上传的 npm 包也会放在这个目录中。@H_696_24@
config.yaml 是用来配置访问权限,代理,文件存储路径等所有配置信息的:@H_696_24@
# # 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 镜像地址:@H_696_24@
> npm install -g nrm # 安装nrm > nrm add XXXX http://XXXXXX:4873 # 添加私有 npm 镜像地址 > nrm use XXXX # 使用私有镜像地址
注意: 不建议使用私有源安装公网 npm 包,安装公网 npm 包请使用 taobao 源@H_696_24@
nrm 其他命令:@H_696_24@
> nrm --Help # 查看nrm命令帮助 > nrm list # 列出可用的 npm 镜像地址 > nrm use taobao # 使用`淘宝npm`镜像地址
> npm adduser # 按提示输入用户名,密码,邮箱即可
登陆 npm 源@H_696_24@
> npm login # 按提示输入用户名,密码,邮箱即可
发布 npm 包@H_696_24@
> cd D:\projects\yourproject # 进入项目目录 > npm publish # 执行发布命令
> npm unpublish <package>@<version> # 例: npm unpublish [email protected]
> npm <owner> rm <user> <package> # 例: npm admin rm test flagwind
查看模块所有者@H_696_24@
> npm <owner> ls <package> # 例: npm admin ls flagwind
在 Windows 下直接执行这个命令会遇到一些问题:@H_696_24@
1、Python 没有安装或版本不对@H_696_24@
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 中。@H_696_24@
> npm config set python C:\Python27\python.exe
2、MSBuild 版本不对@H_696_24@ @H_895_258@mSBUILD : error MSB4132: The tools version "2.0" @H_616_260@is unrecognized. Available too ls versions are "4.0"
解决方案: node-gyp 需要用到 Visual C++ Build Tools,百度搜索并安装即可。@H_696_24@
3、Windows下不支持 fs-ext 和 crypt3@H_696_24@
node-gyp 报编译 fs-ext 和 crypt3 失败的错误,安装 sinopia 时可以忽略,错误信息如下:@H_696_24@
fs-ext.cc(195): error C3861: ‘fcntl‘: identifier @H_616_260@not found [C:\Users\clcaza\ApPDAta\roaR_973_11845@ing\npm\node_modules\sinopia\node_modules\.0.[email protected]\build\fs-ext.vcxproj] crypt3.cc(5): Fatal error C1083: CAnnot open @H_616_260@include file: ‘unistd.h‘: No such file @H_616_260@or directory [C:\Users\clcaza\ApPDAta\roaR_973_11845@ing\npm\node_modules\sinopia\node\_modules\.0.[email protected]\build\crypt3.vcxproj]
解决方案: sinopia 依赖于 fs-ext
和 crypt3
,但这两个包是可选的,搜索并删除 sinopia 安装目录下所有带 fs-ext
和 crypt3
字样的包@H_696_24@
@H_674_2@
来源:https://www.jianshu.com/p/c2a569be60a9@H_696_24@ @H_674_2@
以上是大佬教程为你收集整理的windows 环境部署私有 npm 源全部内容,希望文章能够帮你解决windows 环境部署私有 npm 源所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。