号外号外,我家已建立了快递点,不用再跑镇上了
前序:
- 此搭建整合了网上以及官网的教程。
- 选择自己搭建服务器,一个为公司项目的考虑,公共库有公共库的好处,私有库所能体现的为可控,稳定,安全,当然也跟你选择的库的工具有关。
- 选择verdaccio,一个是它常更新,一个是基于网上大多数教程的sinopia延伸的,一个就是docker的支持,它有docker的镜像,这倒是省了很多东西,最近还是喜欢弄docker,当然还有其他工具可选,请自行查阅,这里仅仅就verdaccio搭建。
- 此处分2个版本,一个是默认版,一个是自定义版(废话最多的版)
前提:
一:步骤:默认版
npm install --global verdaccio
verdaccio --listen 端口号
二:步骤:自定义版
1. 安装 Verdaccio
npm install --global verdaccio
npm install --global verdaccio --registry 源地址
2. 设置 Verdaccio的仓储路径(本人不习惯什么都装到C盘,若是没这种习惯的,请跳过这个步骤)
1.0 选择自己喜欢的盘,创建文件(默认是Verdaccio,当然你喜欢为主,就像我喜欢这样折腾)
2.0 将在c盘存在的配置文件完封不动地剪切到新文件,一般新装才有,其实我更希望它自安装的命令能改为自己定义,那样就不用这么麻烦,当然源码都有了,还是可以改,但是我还是懒,故原始做法,windos的默认路径为
C:\Users\你的登录用户名称\AppData\Roaming\verdaccio
2.1 修改后的目录结构
- Verdaccio
- storage
- config.yaml
- htpasswd(一开始这个不存在,启动后由配置自动生成)
3. 修改配置文件,当然你也可以直接把我这份拿去用,前提是符合安装版本以及你的喜好官网配置栗子
# 设置你存储的包的位置,当前表示和配置文件同目录下的storage
storage: ./storage
# 插件位置
plugins: ./plugins
web:
title: Verdaccio
# comment out to disable gravatar support
# gravatar: false
# by default packages are ordercer ascendant (asc|desc)
# sort_packages: asc
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
# 设置源地址
uplinks:
npmjs:
url: https://registry.npmjs.org/
taobao:
url: http://registry.npm.taobao.org/
packages:
'@*/*':
# scoped packages
access: $all
publish: $authenticated
unpublish: $authenticated
proxy: taobao
# 设置权限,可以限制某些账号浏览和发布包
'**':
# 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/publish packages
# (anyone can register by default, remember?)
publish: $authenticated
unpublish: $authenticated
# 当你的请求的包不在本地库时,会请求下面的代理获取,这里将npmjs改成了淘宝库,当然你也可以改成其他的
proxy: taobao
# You can specify HTTP/1.1 server keep alive timeout in seconds for incoming connections.
# A value of 0 makes the http server behave similarly to Node.js versions prior to 8.0.0, which did not have a keep-alive timeout.
# WORKAROUND: Through given configuration you can workaround following issue https://github.com/verdaccio/verdaccio/issues/301. Set to 0 in case 60 is not enough.
server:
keepAliveTimeout: 60
middlewares:
audit:
enabled: true
# 日志 设置
logs:
- { type: stdout, format: pretty, level: http }
#- {type: file, path: verdaccio.log, level: info}
#experiments:
# # support for npm token command
# token: false
#自定义监听端口,减少命令启动配置
listen: 0.0.0.0:8081
4.CMD窗口启动 Verdaccio 服务(前提为环境变量存在npm的安装目录,否则就得切换到npm的安装目录才能使用这些命令,毕竟这些插件的bat就在这里,还有就是启动这个不要关闭命令窗口,关闭等于退出,故后面会有进程守护工具或者将改服务做成windos服务,那样就可以自启动和服务故障会自动重启服务)
# 默认位置,启动
verdaccio
#配置文件没写listen或者想自己改端口启动的都可以选择此命令
verdaccio --listen 端口号 --config config.yaml的位置
#例:
verdaccio --listen 1111 --config C:\verdaccio\config.yaml
#配置文件已写listen并自定义配置文件的选择此命令
verdaccio --config config.yaml的位置
#例:
verdaccio --config C:\verdaccio\config.yaml
5. 至此搭建完毕,启动的地址为 http://localhost:你设置的端口号/ 当然要是你部署在云服务器或者已经将本地映射到固有域名,就可以域名:你设置的端口号访问了,注意:你得开放该端口,否则外面还是没法访问到,后面会有专门篇节说明怎么使用,欲知后事如何,请看后回分解。
网友评论