在Monorepo中Angular库与Angular模块相比有何优势? NX架构 [英] Benefits of Angular libraries vs Angular modules in a monorepo? NX architecture

查看:476
本文介绍了在Monorepo中Angular库与Angular模块相比有何优势? NX架构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道使用rathen库而不是Angular中的模块有什么好处,因为nx.dev要求使用monorepo体系结构.

I'm wondering what are the benefits of working with libraries rathen than modules in Angular, as nx.dev recommands for an monorepo architecture.

我了解npm可发布功能(例如,另一个仓库将使用的界面)的好处,但是为什么我要从与业务相关的功能(例如主页)中创建一个库,例如:

I understand the benefits for a npm publishable feature like interfaces that another repo will consume, but why would I want to make a library out of a business related feature, like a homepage, for example :

myorg/
├── apps/
│   ├── todos/
│   └── todos-e2e/
├── libs/
      ├── todos/
        ├── home/   <-- why nx recommands making a library here?
          ├── src/
            ├── lib/
              ├── home.component.html/ts/scss
              ├── home.module.ts
├── tools/
├── README.md
├── workspace.json
├── nx.json
├── package.json

而不是

myorg/
├── apps/
│   ├── todos/
         [...]
         ├── home/   <-- just a simple lazy loaded module here
           ├── home.component.html/ts/scss
           ├── home.module.ts
│   └── todos-e2e/
├── libs/
├── tools/
├── README.md
├── workspace.json
├── nx.json
├── package.json
└── tsconfig.json

推荐答案

NX建议您将90%以上的代码存储在libs中,而这些libs的目的不是仅在不同应用程序之间共享代码,即使代码没有共享,我们也可以创建一个lib,并且仅将应用文件夹用于路由和环境之类的配置.

NX recommand that you put more than 90% of your code in libs and the the purpose of those libs is not only sharing code between the different applications we can create an lib even if the code is not shared and use app folders only for configurations like routings and environments.

我们不得不提到将代码分成小单元(库)的好处,您可以单独测试和构建它们.

we have to mention the benefits of separating your code into small units (libs) that you can test and build them individually.

因此,在您的情况下,它可能是一个可以延迟加载到您的应用程序中的库,它可以管理自己的路由,这是从书中摘录的库类型的列表

so in your case it can be a lib that can be lazy loaded into your app it can manage it's own routes, here is the list of libs types taken from their book

  • 功能库:开发人员应将功能库视为可针对特定业务用例或应用程序页面实现智能UI(具有注入服务)的库.

  • Feature libraries: Developers should consider feature libraries as libraries that implement smart UI (with injected services) for specific business use cases or pages in an application.

UI库:UI库仅包含演示组件.

UI libraries: A UI library contains only presentational components.

数据访问库:数据访问库包含用于与后端系统进行交互的服务和实用程序.它还包括与状态管理有关的所有代码.

Data-access libraries: A data-access library contains services and utilities for interacting with a back-end system. It also includes all the code related to State management.

实用程序库:实用程序库包含许多库和应用程序使用的通用实用程序和服务.

Utility libraries: A utility library contains common utilities and services used by many libraries and applications.

当您看到所有这些类型的lib时,您就会明白,主意是在应用程序的libs中拥有最大的代码.

when you see all those types of libs you understand that the idea is to have the max of code in libs insteand of apps.

我邀请您在 Victor Savkin 谈论libs

i invite you to check this when Victor Savkin talked about libs

https://youtu.be/qYNiOKDno_I?t=6m35s

这篇关于在Monorepo中Angular库与Angular模块相比有何优势? NX架构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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