使用node.js npm和git的最佳工作流程 [英] Best workflow using node.js npm and git

查看:103
本文介绍了使用node.js npm和git的最佳工作流程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



在早期的节点项目中,我有一个额外的文件夹供所有人使用我使用的节点模块。这个文件夹被git忽略,我通过git submodules管理版本和更新,这并不容易(没有依赖关系,更新到新版本并不总是很有趣。)



什么我在寻找的是:

npm install packagename

npm dump_modules_into_file



所以参与此项目的其他人都可以这样做:

npm install_or_update_modules_from_file



我不想要 node_modules 由我的git仓库跟踪。基本上我想要类似于symonfy2处理它的东西捆绑包



PS:我知道 npm submodule packagename ,但这个命令不是很有帮助,因为它没有安装依赖关系,它不会更新模块。



PS2:我准备好了 package.json ,但这也有一些缺陷。 (无参数,您必须手动更新模块版本。)

解决方案

package.json

code>将完成你正在寻找的东西。在关于传递 - mongodb:native 标志的注释中,该标志是 npm 命令的参数,<当您在自己的项目中使用 package.json 时, 工作。 mongodb软件包有一个安装脚本,用于在节点处理环境中查找该标志。如果该标志存在,那么它会产生另一个构建过程。所以,如果你在你的package.json中有mongodb作为依赖项,那么


  {
name:MyProject
,description:Test
,version:0.0.1
,dependencies:{
mongodb:*


$ / code>

运行 npm install --mongodb:native will will be working。



关于手工更新 - 这只是第一次可能需要一段时间,并且我相信如果存在很多依赖关系,则可以编写脚本来生成它。然而,这听起来像你有一个相当大的团队,如果是这样的话,那么自动更新 package.json 会变得非常难看(认为新的开发人员,实验特性等)在这部分开发周期中对破坏的构建负责不一定是个坏主意。

参考文献:





编辑:正如Nick提到的那样,将'node_modules'目录添加到 .gitignore 中将阻止任何这些文件被检入您的回购


I am about to do a large project with node.js and currently try sort a few things out.

In earlier node projects I had an extra folder for all node modules I used. This folder was ignored by git and I managed version and updates via git submodules, which was not easy (no dependencies, updating to new version was not always fun.)

What I am looking for is:

npm install packagename
npm dump_modules_into_file

So everyone else who is involved in this project could do:

npm install_or_update_modules_from_file

I don not want to have node_modules tracked by my git repository. Basically I want something similar to how symonfy2 handles it bundles.

P.S.: I know about npm submodule packagename, but this command is not very helpful because it does not install dependencies and it does not update the modules.

P.S.2: I ready about the package.json, but this also has some flaws. (No parameters and you have to update module versions by hand.)

解决方案

package.json will accomplish what you're looking for. In your comment about passing the --mongodb:native flag, that flag is an argument to the npm command and does work when using a package.json in your own project. The mongodb package has an "install script" which looks for that flag in the node processing environment. If that flag is present, then it spawns another process for the build. So, if you have mongodb as a dependency in your package.json

{
    "name": "MyProject"
  , "description": "Test"
  , "version": "0.0.1"
  , "dependencies": {
        "mongodb": "*"
    }
}

Running npm install --mongodb:native will work.

With regards to "updating it by hand" - it's really only the first time that it might take a while, and I'm sure you could write a script to generate it if there are a lot of dependencies. However, it sounds like you have a fairly large team, and if that is the case, then automating the updates to package.json will turn really ugly (think new developers, experimental features, etc.) Having accountability for broken builds in this part of the development cycle isn't necessarily a bad idea.

References:

EDIT: and as Nick mentioned, adding the 'node_modules' directory to .gitignore will prevent any of those files from being checked into your repo

这篇关于使用node.js npm和git的最佳工作流程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆