[英]How to manage internal Node.JS modules
What would be the preferred way to handle internal modules within a node.js application? 在node.js应用程序中处理内部模块的首选方法是什么?
I mean, currently we have a fairly big application and there are several dependencies, installed via npm. 我的意思是,目前我们有一个相当大的应用程序,并且有几个依赖项,通过npm安装。 We have
node_modules
in .gitignore
. 我们在
.gitignore
有node_modules
。 Therefore it's not in the repository. 因此它不在存储库中。 We use
npm shrinkwrap
to freeze the modules versions, so, upon deployment, an npm install
puts together eveything we need into node_modules
. 我们使用
npm shrinkwrap
来冻结模块版本,因此,在部署时, npm install
将我们需要的东西放到node_modules
。
The problem is, since out app is getting bigger, we want to split it to smaller modules. 问题是,由于out app越来越大,我们希望将它拆分为更小的模块。 Now, if I create a
foo
module and put it in node_modues
, I need to allow it in the repo, which does not seem so neat to have both ignored and checked out modules in node_modules
. 现在,如果我创建一个
foo
模块并将其放在node_modues
,我需要在repo中允许它,在node_modules
忽略和检出模块似乎并不那么整洁。
We can not publish these on npm registry because they are not really "public". 我们无法在npm注册表上发布这些内容,因为它们并非真正“公开”。
Is there any obvious solution that I'm not aware of? 有没有明显的解决方案我不知道?
I agree with your aesthetic of not mixing 3rd-party non-repo stuff with your in-house revision-controlled contents. 我同意你不将第三方非回购材料与内部版本控制内容混合的美学。
The NODE_PATH search path variable can help you here, you can use a different directory with contents under revision control. NODE_PATH搜索路径变量可以在这里帮助您,您可以使用不同的目录,其中包含修订控制下的内容。
http://nodejs.org/api/modules.html http://nodejs.org/api/modules.html
Depending on your appetite for flexibility vs complexity, you can consider a build step that actually copies your various node modules from wherever you keep them, into an output directory (probably "named node_modules" but not necessarily). 根据您对灵活性与复杂性的关系,您可以考虑实际将各种节点模块从保存它们的任何位置复制到输出目录(可能“命名为node_modules”但不一定)的构建步骤。
A common solution is to store the modules in a private Git repository somewhere, and then use a git://
URL as a dependency; 一个常见的解决方案是将模块存储在某个私有Git存储库中,然后使用
git://
URL作为依赖项; npm knows how to clone repositories as dependencies. npm知道如何将存储库克隆为依赖项。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.