在5分钟内搭建企业内部私有npm仓库
下面通过三种方法来搭建公司私有npm仓库,每种方式都有自己的优势。
Node.js >= 6.11.3,我的Node版本:node v8.2.1
Linux or OSX,我的系统版本:CentOS Linux release 7.2.1511 (Core)
教程归档在我的Github中欢迎修正和Star
cnpm搭建
安装
npm install -g --build-from-source cnpmjs.org cnpm sqlite3
# 如果报错或者警告通过下面方式安装
npm install -g --unsafe-perm --verbose --build-from-source cnpmjs.org cnpm sqlite3
如果安装不流畅通过下面形式安装:
npm install -g --build-from-source \--registry=https://registry.npm.taobao.org \--disturl=https://npm.taobao.org/mirrors/node \cnpmjs.org cnpm sqlite3
如果报警告或者安装错误,请添加参数--unsafe-perm --verbose
启动并配置服务
管理员:
myname,othername
范围:my-company-name,other-name
默认端口:7001-registry, 7002-web
启动服务
$ nohup cnpmjs.org start --admins='myname,othername' \--scopes='@my-company-name,@other-name' &
设置注册地址
将cnpm默认注册地址更改为私有注册地址
cnpm set registry http://localhost:7001
登录cnpm
$ cnpm login
Username: myname
Password: ***
Email: (this IS public) test@test.com
包上传到私有仓库
新建项目
$ cd /tmp
$ mkdir helloworld && cd helloworld
$ cnpm init
name: (helloworld) @my-company-name/helloworld
version: (1.0.0){"name": "@my-company-name/helloworld","version": "1.0.0","description": "my first scoped package","main": "index.js","scripts": {"test": "echo \"Error: no test specified\" && exit 1"},"author": "","license": "ISC"
}
上传到私有仓库
$ cnpm publish
+ @my-company-name/helloworld@1.0.0
查看预览包
浏览器中预览
open http://localhost:7002/@my-company-name/helloworld
使用cnpm
预览
cnpm info
安装
所有公共包都可直接使用cnpm
安装
cnpm install hotkeys-js
通过verdaccio搭建
verdaccio 是一个轻量级的私有npm代理注册。(sinopia fork)
安装
# 使用 npm 安装
npm install -g npm# 使用 yarn 安装
yarn global add verdaccio
启动服务
verdaccio >> verdaccio.log 2>&1 & # 后台启动并写入日志# Verdaccio doesn't need superuser privileges. Don't run it under root.
# warn --- config file - /root/.config/verdaccio/config.yaml
# warn --- http address - http://localhost:4873/ - verdaccio/2.3.6verdaccio --listen 4000 --config ./config.yaml # 指定配置启动
添加用户/登录
npm adduser --registry http://localhost:4873
上传私有包
npm publish --registry http://localhost:4873
本地配置注册地址
npm config list -l # 查看默认配置
# 将默认地址 https://registry.npmjs.org/ 改成私有地址
npm set registry http://localhost:4873
# 如果您使用HTTPS,请添加适当的CA信息
#(“null”表示从操作系统获取CA列表)
$ npm set ca null
Git仓库当私有npm
这个方法得益于,npm提供的的丰富安装方法。通过下面方法安装:
npm i -S git+ssh://git@git.showgold.cn:npm/hello.gitnpm install -S git+ssh://git@github.com:npm/npm.git#v1.0.27
npm install -S git+ssh://git@github.com:npm/npm#semver:^5.0
npm install -S git+https://isaacs@github.com/npm/npm.git
npm install -S git://github.com/npm/npm.git#v1.0.27
⚠️ 上面安装需要注意:你的工程一定是在某一个组下面建立,方便管理,在生成你的包的时候package.json
中的name
一定要带上范围
建立一个私有模块
# 假设你建立了一个Git仓库,先克隆下来
git clone http://git.your-inc.com/companyfe/hello-private.git# 生成 `package.json` 配置, 注意限定 `@scope` 范围
npm init --scope=companyfe
# 提交到仓库
git push origin master
⚠️ 将得到如下依赖,注意:
name
字段必须限定范围,一般为 GitLab group 的名字, 例如@companyfe
, 那么name
为:@companyfe/hello-private
。
private
设为true
防止将私有模块上传到公网上去,需要手动设置一下。
{"name": "@companyfe/hello-private","version": "1.0.1","description": "","main": "index.js","private":true,"scripts": {"test": "echo \"Error: no test specified\" && exit 1"},"author": "kenny wang <wowohoo@qq.com> (http://wangchujiang.com)","license": "ISC"
}
安装使用私有模块
跟安装开源的模块一样, 使用 npm install
安装依赖即可. 私有模块会安装在 @scope
的子文件夹中, 例如: node_modules/@companyfe/hello-private
.
# 基础安装
npm i -S git+ssh://git@git.your-inc.com/companyfe/hello-private.git
# 带版本信息的,必须通过 git 打 tag
npm i -S git+ssh://git@git.your-inc.com/companyfe/hello-private.git#v1.2.0
将得到如下依赖
{"name": "helloworld","version": "1.0.0","description": "","main": "index.js","scripts": {"test": "echo \"Error: no test specified\" && exit 1"},"dependencies": {"@companyfe/hello-private": "git+ssh://git@git.your-inc.com/companyfe/hello-private.git#v1.2.0"},"author": "kenny wang <wowohoo@qq.com> (http://wangchujiang.com)","license": "ISC"
}
使用私有模块
var hello = require('@companyfe/hello-private');
优劣势
不好的地方是,使用 npm update
是无法更新私有模块,想更新只能重新安装一次。好处是不用搭建服务。
参考资料
- Can I run my own private registry?
在5分钟内搭建企业内部私有npm仓库相关推荐
- Docker搭建企业内部私有云盘/开源网盘系统
转载来源:https://manual-cn.seafile.com/deploy/deploy_with_docker.html Docker搭建企业内部私有云盘/网盘系统 快速搭建 # 执行下面, ...
- CentOS6/7/8搭建企业内部私有yum源仓库服务器
yum私有仓库 内网服务器禁止访问互联网, 但yum安装需要依赖yum源仓库. 在内部网络部署私有yum源仓库, 不但可以保证内网服务器安全, 还可以提高yum查询.下载.安装速度 思路: 把仓库文件 ...
- 如何搭建一个私有npm仓库
业界主流的私有npm仓库搭建的主流方案有如下几种: 付费购买 使用 git+ssh 这种方式直接引用到 GitHub 项目地址 使用 Sinopia 使用 cnpmjs.org 第一种,一是考虑到公司 ...
- (转)搭建企业内部yum仓库(centos6+centos7+epel源)
搭建企业内部yum仓库(centos6+centos7+epel源) 原文:https://www.cnblogs.com/nulige/p/6081192.html https://www.linu ...
- 30分钟快速搭建一套私有云平台
本文介绍一种基于starvcenter快速搭建私有云平台的方法,实现30分钟内完成一套私有云平台的部署. 整个安装过程真的太简单了,仅需4个步骤.话不多说,上干货~ 1.下载starvcenter的i ...
- 五分钟内搭建的混沌电路
简 介: 针对一种简单的混沌电路进行测试,没有能够复现电路的工作状态.具体原因尚未清楚. 关键词: 混沌电路,相移单管电路 #mermaid-svg-QPl6WYe8NnE6m9yt .label{f ...
- 【转载】用开源软件搭建企业内部协作平台, Kill QQ MSN
作为公司的一分子, 您可能忧心忡忡于通过 MSN, QQ 流入的各种名目繁多的病毒, 木马, 例如熊猫烧香, 以及通过 MSN 传播的导致公司网络瘫痪的蠕虫病毒. 换句话说, 我们需要企业内部协作平台 ...
- 搭建企业内部知识库,从知识管理做起
编者按:随着信息化的发展,企业的知识资产越来越重要,搭建企业内部知识库对企业十分重要,本文分析了企业知识库的意义,并进一步介绍了知识管理系统助力企业知识库搭建实现的功能. 概要: (1)搭建企业知识库 ...
- 用开源软件搭建企业内部协作平台, Kill QQ MSN
作为公司的一分子, 您可能忧心忡忡于通过 MSN, QQ 流入的各种名目繁多的病毒, 木马, 例如熊猫烧香, 以及通过 MSN 传播的导致公司网络瘫痪的蠕虫病毒. 换句话说, 我们需要企业内部协作平台 ...
最新文章
- 常量元素记忆口诀_化学口诀表:帮助学生加深记忆提高解题正确率
- 梭子鱼任命James Forbes-May为亚太区销售副总裁
- 敏捷测试理论以及实践(2)
- 两条直线求交点c语言,C§ 3.3.1两条直线的交点坐标(5页)-原创力文档
- 英语四级c语言,2017年大学英语四级精选试题练习
- Css学习总结(2)——60个有用CSS代码片段
- 七年为限 一觉梦已远——我与你的新贵族
- 快点来学吧!Spring事务是如何传播的?快来收藏!
- 系统架构设计-项目管理
- 服务器系统开机提示0xc000007b,0xc000007b蓝屏解决方法
- 存储文件用 云服务器推荐推荐,云存储服务器推荐
- Shell之判断周几
- 使用 Android Studio 内置的模拟器体验原生安卓
- c语言 椭圆,C语言画圆椭圆
- SylixOS设备驱动
- linux打印机验证密码,HP LaserJet Pro打印机远程管理员密码泄露漏洞
- 超级实用——用word与谷歌翻译将英文PDF文档翻译成中文,免费无限制
- 【亲测】如何最优化的下载大量比较旧的资源
- uber优步提高成单率,轻松拿奖励!
- LeetCode每日一题——Day21