加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Windows > 正文

windows 环境部署私有 npm 源

发布时间:2020-12-14 04:28:33 所属栏目:Windows 来源:网络整理
导读:sinopia 是一个零配置带缓存功能的 npm 包管理工具。 sinopia 有以下几个优势值得关注: 不同步拉取 npm 库,占据大量硬盘,没有硬盘被撑爆的问题; 安装配置极其简单,不需要数据库; 支持配置上游 registry 配置,一次拉取即缓存; 支持 forever 及 pm2 守

sinopia 是一个零配置带缓存功能的 npm 包管理工具。

sinopia 有以下几个优势值得关注:

  1. 不同步拉取 npm 库,占据大量硬盘,没有硬盘被撑爆的问题;
  2. 安装配置极其简单,不需要数据库;
  3. 支持配置上游 registry 配置,一次拉取即缓存;
  4. 支持 forever 及 pm2 守护进程管理;

服务器部署

安装

> npm install -g sinopia

启动

> sinopia
    warn  --- config file  - C:UsersjasonAppDataRoamingsinopiaconfig.yaml
    warn  --- http address - http://localhost:4873/

打开 http://localhost:4873/ 如果能正常显示,说明安装成功。

?

?

sinopia 启动时默认会创建 config.yaml 文件,文件路径可以看输出的提示。我们将上面路径的 config.yaml 拷贝到指定盘符的文件夹下,使用 -c 选项指定配置文件,并执行命令:

> sinopia -c D:sinopiaconfig.yaml

现在我们就可以在指定目录下运行了,以后上传的 npm 包也会放在这个目录中。

配置

config.yaml 是用来配置访问权限,代理,文件存储路径等所有配置信息的:

# # 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 源

  1. 需要安装私有 npm 包时,请执行 nrm use sinopia 切换到私有 npm 源
  2. 安装公有 npm 包时,请执行 nrm use taobao 切换到淘宝源安装

nrm 其他命令:

> nrm --help # 查看nrm命令帮助 > nrm list # 列出可用的 npm 镜像地址 > nrm use taobao # 使用`淘宝npm`镜像地址 

常用 npm 命令

注册发布者

> npm adduser                        # 按提示输入用户名,密码,邮箱即可 

登陆 npm 源

> npm login                          # 按提示输入用户名,密码,邮箱即可 

发布 npm 包

> cd D:projectsyourproject # 进入项目目录 > npm publish # 执行发布命令 

删除 npm 包

> npm unpublish <package>@<version>  # 例: npm unpublish [email?protected] 

删除发布者

> npm <owner> rm <user> <package>    # 例: npm admin rm test flagwind 

查看模块所有者

> npm <owner> ls <package>           # 例: npm admin ls flagwind 

安装问题

在 Windows 下直接执行这个命令会遇到一些问题:

1、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:Python27python.exe 

2、MSBuild 版本不对

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 报编译 fs-ext 和 crypt3 失败的错误,安装 sinopia 时可以忽略,错误信息如下:

fs-ext.cc(195): error C3861: ‘fcntl‘: identifier not found [C:UsersclcazaAppDataRoamingnpmnode_modulessinopianode_modules.0.[email?protected]buildfs-ext.vcxproj] crypt3.cc(5): fatal error C1083: Cannot open include file: ‘unistd.h‘: No such file or directory [C:UsersclcazaAppDataRoamingnpmnode_modulessinopianode_modules.0.[email?protected]buildcrypt3.vcxproj] 

解决方案: sinopia 依赖于 fs-extcrypt3,但这两个包是可选的,搜索并删除 sinopia 安装目录下所有带 fs-extcrypt3 字样的包

来源:https://www.jianshu.com/p/c2a569be60a9

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读