简体   繁体   English

在项目中有多个package.json可以吗?

[英]is it ok to have more than one package.json in a project?

Is it ok to have more than one package.json in a project? 在项目中有多个package.json可以吗? I'm working in a .NET MVC solution and it has a package.json at the root level. 我正在使用.NET MVC解决方案,它在根级别有一个package.json。 I need to integrate Jasmine/Karma into the solution and this is my first time doing this type of integration. 我需要将Jasmine / Karma集成到解决方案中,这是我第一次进行这种集成。 I found a sample project for Jasmine/Karma on the web and I was able to get this running locally. 我在网上找到了Jasmine / Karma的示例项目,我能够在本地运行。 This project has it's own package.json. 这个项目有自己的package.json。

It seems like it would be useful to maintain the package.json file for the sample Jasmine/Karma sample project separately from the package.json at the root level of the solution to provide more flexibility and to allow the same properties to be used differently based on context. 似乎将示例Jasmine / Karma示例项目的package.json文件与解决方案的根级别的package.json分开维护是有用的,以提供更大的灵活性并允许基于不同的方式使用相同的属性在背景上。

Would this be valid or generally considered an ok practice? 这是有效的还是通常被认为是一种好的做法? Or do I need to figure out how to merge the contents of package.json from the sample project into the package.json at the root level of the .NET MVC solution? 或者我是否需要弄清楚如何将示例项目中package.json的内容合并到.NET MVC解决方案根级别的package.json中?

I would say its typically bad practice to have more than one package.json. 我会说拥有多个package.json通常是不好的做法。 I would only expect to have to npm install once, and having to deal with two sets of dependency management could lead to issues down the line. 我只希望安装一次npm,并且必须处理两组依赖关系管理可能会导致问题。

In terms of keeping things simple, it is easier to only have to maintain a single package.json file, but there is nothing inherently wrong with multiple package.json files within a repo. 在保持简单方面,只需要维护一个package.json文件就更容易了,但是repo中的多个package.json文件没有任何内在错误。 Some companies do use mono-repos, for which it would make total sense to have multiple package.json files. 有些公司确实使用mono-repos,因此拥有多个package.json文件是完全合理的。

Multiple package.json files give you a lot of flexibility to run different/incompatible versions of dependencies. 多个package.json文件为您提供了很多灵活性来运行不同/不兼容的依赖项版本。 As a practical example, on one of the projects that I work on we have 2 package.json files, one for the main application code and then another one for our BDD tests. 作为一个实际的例子,在我工作的一个项目中,我们有2个package.json文件,一个用于主应用程序代码,另一个用于我们的BDD测试。 We use chimp for our BDD tests and had issues with running that on the latest node version, whereas we don't want to keep the rest of the app from upgrading just because of this. 我们在我们的BDD测试中使用黑猩猩,并且在最新的节点版本上运行它时遇到了问题,而我们不希望仅仅因为这个原因而保持应用程序的其余部分不会升级。 We also found that the single package.json file got very messy when it was combined at first. 我们还发现单个package.json文件在最初合并时变得非常混乱。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM