npm 安装 github 项目的几种方式
1、git+ssh
注意:这个协议需要对应仓库有你的 ssh-key
示例:
npm i -D git+ssh://git@github.com/linlif/npm-test.git
2、git+https
// 注意:这个协议在非开源/私有仓库中需要加上可登录成功的用户名密码
// 示例1(开源):
npm i -D git+https://github.com/linlif/npm-test.git
// 示例2(私有):
npm i -D git+https://[username]:[pwd]@git.github.com/linlif/npm-test.git
使用npm link 调试本地npm包
测试项目名称:my-project,npm包名称:my-utils
1、my-project 在 my-utils 项目目录下,例如:my-project/src/public/my-utils:
# cd path/to/my-project
# npm link ./src/public/my-utils
2、my-project 和 my-utils 不在同一个目录下
// 先去到my-utils模块目录,把它 link 到全局
# cd path/to/my-utils
# npm link
// 再去项目目录通过包名来 link,需要注意的是,my-project项目的node_modules目录中不要有my-utils包,如果有请删除
# cd path/to/my-project
# npm link my-utils
- 取消/删除npm link的包
// 取消link(取消 my-project 和 my-utils 的 link 关系)
# cd path/to/my-project
# npm unlink my-utils
// 删除link(删除全局 my-utils 的 link)
# cd path/to/my-utils
# npm unlink my-utils
参考文档 :