简体   繁体   English

Angular 工作区 - 我可以在多个 package.json 中分离依赖项吗?

[英]Angular workspace - Can I seperate dependencies in multiple package.json?

The Angular Workspace allows me to use add several projects into a mono-repo, which is great. Angular 工作区允许我将多个项目添加到单一存储库中,这很棒。 However, working with several teams, I have noticed that it can get really messy if you only have one package.json and have each team edit that with the app they are writing.但是,与多个团队合作时,我注意到如果您只有一个 package.json 并且让每个团队使用他们正在编写的应用程序编辑它,它会变得非常混乱。

Is it possible to have a struture like this?有没有可能有这样的结构?

|── angular.json
├── browserslist
├── e2e
├── karma.conf.js
├── node_modules
├── package.json <--- I should only be responsible for everything in /src
├── package-lock.json
├── projects
│   └── my-sub-application
│       ├── browserslist
│       ├── karma.conf.js
│       ├── package.json <--- Is this possible? So that "my-sub-application" only pulls its dependencies from this package.json?
│       ├── src
│       │   ├── app
│       │   ├── assets
│       │   ├── environments
│       │   ├── favicon.ico
│       │   ├── index.html
│       │   ├── main.ts
│       │   ├── polyfills.ts
│       │   ├── styles.scss
│       │   └── test.ts
│       ├── tsconfig.app.json
│       ├── tsconfig.spec.json
│       └── tslint.json
├── README.md
├── src
│   ├── app
│   ├── assets
│   ├── environments
│   ├── favicon.ico
│   ├── index.html
│   ├── main.ts
│   ├── polyfills.ts
│   ├── styles.scss
│   └── test.ts
├── tsconfig.app.json
├── tsconfig.json
├── tsconfig.spec.json
└── tslint.json

The idea is to have a package.json for each sub application, as it allows for teams to update their dependencies independently.这个想法是为每个子应用程序都有一个 package.json,因为它允许团队独立更新他们的依赖项。 Is that possible?那可能吗?

I think the answer is "yes and no".我认为答案是“是和否”。
As long as you want to stay with ONE application (one build, one artefact), then the answer is no.只要您想使用一个应用程序(一个构建,一个人工制品),那么答案是否定的。

But, if your teams are working on different, seperated, features, it may be worth to think about creating multiple libraries ( https://angular.io/guide/creating-libraries ).但是,如果您的团队正在处理不同的、独立的功能,则可能值得考虑创建多个库( https://angular.io/guide/creating-libraries )。

Each Lib will have its own package.json.每个 Lib 都有自己的 package.json。 But before you go this step, i think you should analyze your dependency structure (and the business use cases), to make sure that the code of a future library is not depending on things outside of it.但是在你走这一步之前,我认为你应该分析你的依赖结构(和业务用例),以确保未来库的代码不依赖于它之外的东西。

You COULD have a kind of dependency tree ( Main app uses Lib-A and Lib-B, Lib-A and Lib-B uses Lib-C,...) but you should check to have no cyclic dependencys, and a "lower" lib should never be dependent on a "higher" lib.你可以有一种依赖树(主应用程序使用 Lib-A 和 Lib-B,Lib-A 和 Lib-B 使用 Lib-C,...)但你应该检查没有循环依赖,以及“较低的" lib 永远不应该依赖于“更高”的 lib。

The approach with libs has major impact on the developing process.使用 libs 的方法对开发过程有重大影响。 A different build process, a more divided / seperated code base, it may effect the code design in many ways, ...一个不同的构建过程,一个更加分割/分离的代码库,它可能会以多种方式影响代码设计,......
So its not a small change.所以这不是一个小的变化。 But it also gives you a lot of Pros.但它也给了你很多优点。
So could a lib get new versions, while other parts of the application will still use the old one until those teams are ready for an upgrade.因此,一个库可以获得新版本,而应用程序的其他部分仍将使用旧版本,直到这些团队准备好升级。 The seperation into libs make the whole application less breakable, because the libs will only talk to each other over defined interfaces.分离成库使整个应用程序更不容易被破坏,因为库只会通过定义的接口相互交谈。 ... ...

So yes, you could have multiple package.jsons.所以是的,你可以有多个 package.jsons。 But its like having multiple small projects.但它就像有多个小项目。 With all its advantages and disadvantages.具有所有优点和缺点。

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

相关问题 Angular 6更新package.json中的过时依赖项 - Angular 6 updating outdated dependencies in package.json Angular package.json和未满足的对等依赖项 - Angular package.json and unmet peer dependencies Angular2 package.json依赖关系? - Angular2 package.json Dependencies? 解决生产构建的 angular package.json 依赖项时的问题 - Issues when resolving angular package.json dependencies for a production build 如何解决 ENOENT:没有这样的文件或目录,在具有多个项目的工作区中使用 ngx-build-plus 打开“\package.json”? - How to solve ENOENT: no such file or directory, open '\package.json' with ngx-build-plus in workspace with multiple projects? 这个package.json文件的格式是否与此依赖项相关 - Is this package.json file well formatted with this dependencies 如何从 package.json 安装依赖项? - How to install dependencies from package.json? NPM-解决Package.json中的对等依赖项 - NPM - Resolving Peer Dependencies in Package.json 有没有一种方法可以将 object 与 package.json 项目的 ZD18B8624A0F5F721DA7B826 文件的依赖项分开? - Is there a method to separate dependencies object from package.json file of an angular project? 将package.json中的所有组织/范围(@angular)依赖项安装/升级到相同版本 - Install / upgrade all organization / scope (@angular) dependencies in package.json to same version
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM