經過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
相關文章
相關標籤/搜索