简体   繁体   English

是否有可能对 nx 库进行 conatinerise

[英]Is it possible conatinerise the nx library

I have a nx library which is used by many nx apps inside the monorepo.我有一个 nx 库,monorepo 中的许多 nx 应用程序都使用它。 Let's say 5 apps using that library.if I made any change in the library.假设有 5 个应用程序使用该库。如果我对库进行了任何更改。 Currently we deploying all the 5 apps.is there an way to only deploy the library and all the apps can consume it automatically without deploying them.目前我们部署了所有 5 个应用程序。有没有一种方法可以只部署库,所有应用程序都可以自动使用它而无需部署它们。

In NX, Apps can be seen as deployable artifacts, whilst libs are pieces of functionality that are consumed by Apps.在 NX 中,应用程序可以被视为可部署的工件,而库是应用程序使用的功能片段。

You could potentially convert your 1 library into an app to containerise it to be consumed by your other Apps at runtime which would mean that your Apps wouldn't need to be redeployed, but this would mean injecting your deployed.js files into your HTML files.您可能会将您的 1 个库转换为一个应用程序以将其容器化以在运行时由您的其他应用程序使用,这意味着您的应用程序不需要重新部署,但这意味着将您的 deployed.js 文件注入您的 HTML 文件. If you were to take this approach your Apps and your deployed Lib-App would need to know nothing about each other as Apps shouldn't reference each other.如果您采用这种方法,您的应用程序和您部署的 Lib-App 将不需要相互了解,因为应用程序不应相互引用。 I don't recommend this option.我不推荐这个选项。

Another option would be to create a publishable library and import this into your Apps from a private registry.另一种选择是创建一个可发布的库并将其从私有注册表导入到您的应用程序中。 However, this would still require deployments of all your Apps, but you would have the option of when you wanted to increment the version number of your published Lib.但是,这仍然需要部署所有应用程序,但您可以选择何时增加已发布库的版本号。 This is rather anti-nx, and I don't recommend this option either.这是相当反nx的,我也不推荐这个选项。 Here is a link anyway: Publishable and Buildable Nx Libraries这里有一个链接: Publishable and Buildable Nx Libraries

However, I think this question is more likely the result of lengthy deployment times and frequent changes to your Libs.但是,我认为这个问题更有可能是部署时间过长和库频繁更改的结果。 If so, I would consider these points.如果是这样,我会考虑这些要点。

  • Changing a Lib that is used by many Apps, also changes those Apps, hence those changes should be tested and deployed.更改许多应用程序使用的库也会更改这些应用程序,因此应对这些更改进行测试和部署。

  • If an App is not changed by a change in the Lib it is consuming, why is it consuming it?如果一个 App 没有被它正在消费的 Lib 的变化所改变,它为什么要消费它? Could that Lib be broken down into smaller Libs to reduce dependencies?是否可以将该库分解为更小的库以减少依赖性?

  • Could you create a collection of Libs that are specific for each App?你能为每个应用程序创建一个特定的库集合吗? An example layout could be:示例布局可以是:

/nx
-/apps
--/app1*
--/app2*
-/libs
--/apps
---/app1
----/pages
-----/page1*
----/ui
-----/component1*
----/services
-----/service1*
---/app2
----/pages
-----/page1*
----/ui
-----/component1*
----/services
-----/service1*
--/ui
---/component1*
--/services
---/service1*

// Where each starred line is a separate library. By doing this you will reduce the number of applications your change will affect, and as a result there will be fewer deployments.
  • If you need to make a change to a library that is used by many apps, and you don't want to deploy them all out at the same time, consider creating a new library and referencing that new library in the App as you want to deploy it.如果您需要对许多应用程序使用的库进行更改,并且您不想同时部署它们,请考虑创建一个新库并根据需要在应用程序中引用该新库部署它。

  • Try not to include any code in an App that you could include in a Lib.尽量不要在 App 中包含任何可以包含在 Lib 中的代码。 It will reduce testing burden as only the Libs that have been affected by a change will need to be tested.它将减少测试负担,因为只有受更改影响的库才需要进行测试。

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

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