首页 > 编程知识 正文

如何搭建私有云服务器,搭建私有邮箱服务器

时间:2023-05-06 18:01:34 阅读:203722 作者:3717

verdaccio 搭建 npm 服务器

为什么要搭建npm 服务器

原因:

公司内部开发的私有包,统一管理,方便开发和使用,自然也可以使用npm 的付费服务,原谅我们的穷安全性,由于公司内部开发的模块和一些内容并不希望其他无关人员能够看到,但是又希望内部能方便使用加速,自己搭建npm 服务器,本身可以自带常用package的缓存, cnpm 有一些包存在路径问题,而npm 的速度有些感人,自建的服务器会缓存下载过的包,能节省时间

搭建方法 使用verdaccio

verdaccio 是 sinopia 开源框架的一个fork ,但是由于sinopia 两年前就已经没有人维护了,由于网上搜的都是sinopia,但我实际使用了一波后,坑不要太多,哭死…….. 而且由于没人维护,所有bug ,什么的自己去看源码解决吧, 所以果断弃坑, 找到了这个verdaccio

安装

使用npm 全局安装即可

npm install –global verdaccio

运行

安装完成后直接输入 verdaccio 命令即可运行

verdaccio
运行示例

后面的yaml 是默认的配置文件,4873端口表示默认端口,现在我们可以通过修改默认的配置文件来符合我们的需求.

verdaccio的全部配置

默认配置如下图所示

# #号后面是注释# 所有包的缓存目录storage: ./storage# 插件目录plugins: ./plugins#开启web 服务,能够通过web 访问web: # WebUI is enabled as default, if you want disable it, just uncomment this line #enable: false title: Verdaccio#验证信息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# a list of other known repositories we can talk to#公有仓库配置uplinks: npmjs: url: https://registry.npmjs.org/packages: '@*/*': # scoped packages access: $all publish: $authenticated #代理 表示没有的仓库会去这个npmjs 里面去找 , #npmjs 又指向 https://registry.npmjs.org/ ,就是上面的 uplinks 配置 proxy: npmjs '**': # 三种身份,所有人,匿名用户,认证(登陆)用户 # "$all", "$anonymous", "$authenticated" #是否可访问所需要的权限 access: $all #发布package 的权限 publish: $authenticated # 如果package 不存在,就向代理的上游服务发起请求 proxy: npmjs# To use `npm audit` uncomment the following sectionmiddlewares: audit: enabled: true# 监听的端口 ,重点, 不配置这个,只能本机能访问listen: 0.0.0.0:4873# log settingslogs: - {type: stdout, format: pretty, level: http} #- {type: file, path: verdaccio.log, level: info} 如何使用

#当前npm 服务指向 本地
npm set registry http://localhost:4873
# 注册用户
npm adduser –registry http://localhost:4873

按照提示输入userName 和 password,email

输入后就注册完成,

#查看当前用户,是否是注册用户.
npm who am i

最后一步就是创建一个文件夹,按照npm publish 的标准格式,创建一个私有的package

# 发布包
npm publish

就成功发布了一个私有的包,

就可以在其他模块里面使用 npm install [package name] 来安装了,
而私有npm 里面不包含的包,例如你要安装一个vue ,webpack 这样的包,找不到的话,会被代理到 npm.js 官网去下载,并且会帮你缓存在 ./storage 文件夹里面. 再次下载,就能体验飞一般的速度了,当一个小团队使用的时候效果更佳.

自然如果你还是不喜欢npm ,想用cnpm ,那么可以去修改配置

uplinks: npmjs: url: https://registry.npmjs.org/packages: '@*/*': #npmjs 又指向 https://registry.npmjs.org/ ,就是上面的 uplinks 配置 proxy: npmjs#常用的仓库地址 npm ---- https://registry.npmjs.org/ cnpm --- http://r.cnpmjs.org/ taobao - https://registry.npm.taobao.org/ nj ----- https://registry.nodejitsu.com/ rednpm - http://registry.mirror.cqupt.edu.cn/ npmMirror https://skimdb.npmjs.com/registry/ edunpm - http://registry.enpmjs.org/

由于考虑到时常会切换仓库来源,我是用了nrm ,一个仓库管理器,实际上就是 简化以下命令

npm set registry [url]

大致上就是如此啦.
如果有错误或者疑惑之处,欢迎留言交流

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。