经过git安装npm私有模块

需求分析

在平常项目中,会有几个项目共同的组件或者工具函数库。这些代码若是在各个项目中都copy一份的话,若是有须要改动的话,oh,要累死去。
本着DPR的原则,须要一种能够管理公用代码的方法。而且代码中有些是公司内部业务逻辑,这确定不能发布成公用包。因此须要一种私有包管理方案。git

可选方案

  • 一、npm官方私有包,须要收费,passgithub

  • 二、搭建npm私有服务器,尚未这个必要,passnpm

  • 三、使用 npm 安装 git 仓库 简单便利json

  • 四、使用 gitsubmodule,在主仓库中嵌套子仓库bash

npm 安装 git 仓库

由于github私有仓库须要收费,这里我使用码云建立免费私有 git 仓库。
在项目中直接 npm 安装私有仓库,示例:服务器

npm install git+ssh://git@github.com:ltinyho/test.git

能够使用npm install --help查看install命令(npm@5.3.0)ssh

npm install (with no args, in package dir)
 npm install [<@scope>/]<pkg>
 npm install [<@scope>/]<pkg>@<tag>
 npm install [<@scope>/]<pkg>@<version>
 npm install [<@scope>/]<pkg>@<version range>
 npm install <folder>
 npm install <tarball file>
 npm install <tarball url>
 npm install <git:// url>
 npm install <github username>/<github project>

从git安装能够选择标签|分支|commit,最好更该代码后修改仓库中package.json版本信息函数

npm install <github username>/<github project>#<tag|branch|commit>

git submodule 仓库嵌套

git submodule add <仓库地址> <文件路径>
在项目根目录生成`.gitmodules`文件,记录子模块的信息

新项目安装或者更新工具

git submodule init 
git submodule update
相关文章
相关标签/搜索