大惠安网

大惠安网

大惠安网

npm私有仓库搭建

背景

  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: 这个是本地的 配置文件 信息(改这个)

posted @ 2017-07-07 12:37  </script>  阅读(49290)  评论(0编辑  收藏  举报

大惠安网

大惠安网

大惠安网

大惠安网

大惠安网

大惠安网

大惠安网

大惠安网

大惠安网

大惠安网

大惠安网

大惠安网