Javascript 一个包中有多个 package.json 文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14246977/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Multiple package.json files in one package
提问by uglymunky
I have a site running on php that uses Node for a few development tasks. Currently, our team relies on puppet to install the node modules that we use for these development tasks, however, I was thinking of moving to using a package.json file in the root of the site instead.
我有一个在 php 上运行的站点,它使用 Node 执行一些开发任务。目前,我们的团队依靠 puppet 来安装我们用于这些开发任务的节点模块,但是,我正在考虑改用站点根目录中的 package.json 文件。
My problem is this:
我的问题是这样的:
My php app is actually 3 separate sites that we have mixed into one (1 public facing site, 1 internal site, 1 client facing site) and its a likely scenario that some installations of the app depend on different node packages (or different versions of the same pacakge). While I know it would be nice to split these apps apart and have each one manage its own dependencies, short of this, is there some way to have multiple package.json files in one site?
我的 php 应用程序实际上是 3 个单独的站点,我们已将它们混合成一个(1 个面向公众的站点、1 个内部站点、1 个面向客户端的站点),并且可能的情况是应用程序的某些安装依赖于不同的节点包(或不同版本的相同的包装)。虽然我知道将这些应用程序分开并让每个应用程序管理自己的依赖项会很好,但除此之外,是否有某种方法可以在一个站点中拥有多个 package.json 文件?
In other words:
换句话说:
/package.json
/site1/package.json
/site2/package.json
/site3/package.json
Or perhaps, is there a way to have the one package.json handle dependencies for more than one app?
或者,有没有办法让一个 package.json 处理多个应用程序的依赖项?
I don't know if this makes sense, let me know if I'm just way out in left field here. Thanks!
我不知道这是否有意义,让我知道我是否只是在这里的左场出路。谢谢!
回答by hunterloftis
As far as I have seen, package.json deals with a single directory's dependencies (and a single instance of node_modules).
就我所见,package.json 处理单个目录的依赖项(以及 node_modules 的单个实例)。
Your best bet is to split your applications into separate directories.
最好的办法是将您的应用程序拆分到单独的目录中。
Barring that, you could just add all of the dependencies to a single package.json file. It will install into the node_modules folder and any app within that directory will have access to all of the installed modules.
除此之外,您可以将所有依赖项添加到单个 package.json 文件中。它将安装到 node_modules 文件夹中,该目录中的任何应用程序都可以访问所有已安装的模块。

