背景

  1. Node.js开发本地项目,有时不同项目之间存在依赖,如果不想把项目发布到npm社区的仓库,则需要有自己本地的仓库。
  2. 有些公司采用的是内网开发,很多npm资源无法从内网去下载。

sinopia(主流)

使用文件系统作为存储,仅保存用户需要的包,如果本地仓库没有对应的包,则从指定的registry下载,默认为npmjs.org,可以改成淘宝的镜像。

安装

Sinopia的安装比较简单,只需使用npm一条安装命令即可:

npm install -g sinopia 或者 yarn global add sinopia

安装遇到问题

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 python2.7

2.不支持fs-ext和crypt3



只要有出现以上图的或者 其他关于crypt3的问题的话, 看下面解决方法

查看sinopia源码(看你安装在哪)里的package.yaml

optionalDependencies:
# those are native modules that could fail to compile
# and unavailable on windows
fs-ext: '>=0.4.1 <1.0.0-0'
crypt3: '>=0.1.6 <1.0.0-0' # for sinopia-htpasswd

删除sinopia安装目录node_modules里的fs-ext和crypt3相关的包,否则执行npm添加用户和登陆验证时会报错。包括:.0.2.0@crypt3,.0.6.0@fs-ext,crypt3和fs-ext以及sinopia-htpasswd\node_modules下的crypt3和fs-ext

使用

启动: sinopia



你也可以打开 地址看一下http://localhost:4873/



就说明成功了

换npm 源

npm config set registry http://xxx.xx.xx.xx:4873/
//xxx.xx.xx.xx 为自己的ip

建议使用用 nrm

npm install -g nrm # 安装nrm
nrm add name http://XXXXXX:4873 # 添加本地的npm镜像地址
nrm use name # 使用本址的镜像地址 name为你要增加的地址

新建用户

npm adduser
Username: test
Password: test
Email: (this IS public) xxx@xxxx

然后就可以发布包了

npm publish     // 在自己要发布的包 路径打这个命令

这边发布的包可以 是自己写的一些资源 或者是其他的 但是要根据npm 包的规范

本人配置文件

#
# 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: 1000
max_users: 1000 # 默认为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 #这个去掉的话,sinopia 将不去下载依赖包 如果只是要放自己资源仓库的话就去掉
# # 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 # 默认没有,只能在本机访问,添加后可以通过外网访问。

注意:配置文件 是在你的用户名 如:本人就admin 找到目录就可以了 (win)

storage: 仓库保存的路径

htpasswd: 保存密码信息 只有新建用户后才 有这个文件

config.yaml: 这个是本地的 配置文件 信息(改这个)

最新文章

  1. [c++] Operator overloading
  2. 【工匠大道】Git的使用总结
  3. Windows server 2012 AD DS 搭建步骤
  4. MVC、ORM、CURD、ActiveRecord、单一入口的概念
  5. 2. MongoDB基本操作 —— 用Mongo.exe操作数据库增删改查
  6. document.documentElement.clientWidth
  7. ci 4.2
  8. 利用SpannableString设置文本
  9. Sql Server2005 Transact-SQL 窗口函数(OVER)
  10. 研究OpenRisc的高人,几十篇文章
  11. java下tcp的socket连接
  12. javascript中遍历EL表达式List集合中的值
  13. c++ cout 保留小数点位
  14. BZOJ 3544: [ONTAK2010]Creative Accounting [set]
  15. CTF中常见密码题解密网站总结
  16. nodejs学习以及SSJS漏洞
  17. pandas常用函数之shift
  18. 测试一下多线程同时往list中添加元素会不会出问题
  19. C#4.0 HTTP协议无法使用TLS1.2的问题
  20. js实现oss文件上传及一些问题

热门文章

  1. freepbx对接gms网关
  2. prometheus安装、使用
  3. XML 实体
  4. java将list转为树形结构的方法
  5. TCP连接、Http连接与Socket连接
  6. PL/SOL csv格式导出查询结果时出现某些列的数据被四舍五入了的解决办法
  7. firefox native extension -- har export trigger
  8. 一张图解决Struts2添加源码
  9. UML——六大关系整理
  10. python单链表