分叉和更改 NPM 包

Forking and changing an NPM package

我一直在为 angular-4 使用支持拖放对象 (ng2-drag-drop) 的 NPM。我发现缺少的功能并决定将其添加到包中。

我所做的是分叉原始项目并添加我的更改。在 commit/push 到我的 git 之后,我使用以下命令安装我的 NPM:

npm install https://github.com/..... --save

NPM 安装成功,但是当查看我的 node_modules 时,我发现源文件丢失了,我只有根目录,包括 package.json 和一些其他文件。缺少任何源文件。

然后我尝试直接从作者 git 安装 NPM,而不是 运行 :

npm install ng2-drag-drop --save

我用过

npm install https://github.com/ObaidUrRehman/ng2-drag-drop.git --save

我的叉子也有同样的问题。

为什么作者 git 和指定包的安装不同?它不是从同一位置获取文件吗?如果没有,我应该怎么做才能让它发挥作用?

您看不到 src 文件夹的原因是

如果您看到 git 存储库,您会发现两个文件 gitignore & npmignore

在该 npm ignore 文件中,您会发现 src 已被忽略,以防止在 运行 npm 命令时将其添加到包中。

将文件从包中取出

Use a .npmignore file to keep stuff out of your package. If there's no .npmignore file, but there is a .gitignore file, then npm will ignore the stuff matched by the .gitignore file. If you want to include something that is excluded by your .gitignore file, you can create an empty .npmignore file to override it. Like git, npm looks for .npmignore and .gitignore files in all subdirectories of your package, not only the root directory.

您需要覆盖这些设置才能在执行 npm install 时获取节点模块中的 src 内容