Git 依赖 npm 保存 .git 文件

Git dependency with npm keeping .git files

我正在使用私有 GIT 存储库作为 npm 中的依赖项:

"name": "git+ssh://git@git.domain.com:user/repo.git"

这是有效的,当我 npm install 时,它会在 node_modules 中克隆存储库。

问题是它删除了 .git 文件夹和 .gitignore 文件。我想保留这些文件(以便稍后提交)¿如何保留这些文件?

听起来您最好保留项目的本地签出并使用本地路径指定依赖项。

cd ..
git clone ssh://git@git.domain.com:user/repo.git
cd repo; npm install
cd ../PROJECT
npm i --save ../repo

这样您就可以进行更改并将它们提交回去。

npmnode_modules 的内容视为私有的,因此您不应期望能够进入 node_modules 目录并做任何有用的事情。如果你想维护一个项目的 git 签出,这是一个依赖项,那么就这样做,但不要将它与 npm 所做的依赖项管理结合起来。

同时检查 npm link 依赖项本身是否是 npm 兼容包。 https://docs.npmjs.com/cli/install

最好在 git 克隆依赖库后使用 npm link ../path-to-local-git

git clone <repo>
cd PROJECT
npm link ../<repo>

您会看到构建过程 运行。