如何使用 NPM 处理 git 项目中的 Node.js 依赖项?
我已经多次遇到这种情况,但仍然没有找到答案。我正在启动一个新的 Node.js 项目,该项目将依赖于其他一些库。为了方便讨论,我们假设有些是纯粹的 JS 库,可以作为 git 子模块添加到新项目中,但有些则需要一些额外的工作(例如 npm 安装的系统依赖项,或必须编译的 C 库) )。
启动这个项目并将其添加到 git 的最佳方式是什么,需要满足以下两个要求:
- 其他人的库没有提交到我们自己的存储库,而是子模块或动态拉入并由 npm 安装。
- 不需要有一大堆必须遵循的指令列表来克隆存储库并拥有一个工作环境。运行 git submodules update --init --recursive 可以,运行 npm 命令来读取 package.json 并安装依赖项也可以(这样的命令存在吗?),但强制每个人都运行“npm install 每个依赖项的 __" 都是不行的,如果不需要的话,我宁愿不使用 'make' 或 'ant' 来做到这一点。
有什么最好的方法来做到这一点的想法吗?这看起来是一件简单、基本的事情,但我找不到我想要做的事情的一个例子。
编辑:语法
I've run into this scenario quite a few times and still haven't found the answer. I'm starting a new Node.js project, and this project will be dependent on some other libraries. For sake of argument, let's say that some are purely JS libraries that could be added as git submodules in the new project, but some have pieces that need some extra effort (such as system dependencies that npm installs, or C libraries that must be compiled).
What's the best way to start this project and add it to git, with the following two requirements:
- Other people's libraries aren't committed to our own repo, and are instead submodules or are pulled in dynamically and installed by npm.
- Not needing to have a big list of instructions that have to be followed just to clone the repo and have a working environment. Running git submodules update --init --recursive is fine, running an npm command to read package.json and install the dependencies is fine (does such a command exist?), but forcing everyone to run through an "npm install __" of every single dependency isn't ok, and I'd rather not use 'make' or 'ant' to do that if I don't have to.
Any thoughts of the best way to do this? It seems like such a simple, basic thing, but I couldn't find a single example of what I'm trying to do.
Edit: Grammar
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
编辑 忽略下面,但留下参考。有时我早上并没有想清楚:)
创建一个
package.json
文件,添加你的依赖项,你的安装就变成了:从你的项目目录。
git 忽略
所有添加的项目。它通过
git submodule
将包安装到node_modules
中,这样 github 等就会识别出它们是链接的。只要 npm 包包含 git URI,这就会起作用。不幸的是,很多人都没有这样做,所以你在这些方面运气不好。另请注意,当您执行此操作时,
npm
将不再在该模块上工作,例如您无法通过npm
进行更新,您必须通过 < code>git或者你可以这样做:
./modules.js
./make
edit Ignore below, but left for reference. Sometimes I don't think clearly in the morning :)
make a
package.json
file, add your dependencies and your install simply becomes:from your project directory.
git ignore
all the added projects.It installs the packages into
node_modules
viagit submodule
so github, etc will recognize that they're link. This works whenever the npm package has a git URI included. Unfortunately a good number don't, so you're out of luck on those.Also, note that when you do this,
npm
won't work on the module any longer, e.g. you can't update vianpm
, you have to do it viagit
Or you could just do something like:
./modules.js
./make