角模块与库 [英] Angular Module vs. Library

查看:115
本文介绍了角模块与库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

太棒了,Angular发布了版本6,CLI提供了生成库的选项-他们称其为备受期待的功能。

So great, the Angular has released version 6 and the CLI provides an option to generate libraries - something that they call a "highly anticipated feature".

现在,从业务的角度来看,我想知道:

Now, coming from a business perspective, I am wondering:


  • 为什么您实际上需要这个,

  • 为什么在一个现有项目中而不是一个单独的项目,您可以通过npm像往常一样安装一个项目...

  • ,如果您想在项目中使用它,为什么不为此使用模块。 / li>
  • why you would actually need this,
  • why inside of an existing project and not a separate which you can install as usual via npm...
  • and if you want this inside your project, why not use a module for that.

所以我明白了,在npmjs上发布了一些东西,希望整个世界以及未来的连接事物都需要它。库,很棒。

So I get it, publish something on npmjs and hope the whole world and future connected things need exactly that. Library, great.

在一家更大的公司的大型系统中,我们可以重用库,但是我们已经能够使用模块重用东西。

Inside a big system in a even bigger company, we could reuse a library but we already were able to reuse stuff with a module. I need to build the lib separately and recompile every time I change something..

使用库而不是模块的原因是什么?

What are the reasons to use a library instead of a module?

(目前,我想说一个lib甚至可以大于一个模块,所以我会 just 使用它更好地组织我的应用程序)

(Currently I'd say that a lib can be even bigger than a module, so I would just use it to organize my application better)

推荐答案

这个网站我找到了一个很好的解释。

On this website I found a great explanation.

驻留在项目中的 中,让我们将属于一起的组件捆绑在一起。我们可以在需要的地方导入该模块,而不是在根级别声明所有组件。即AuthModule可以处理所有与auth相关的内容。

Reside inside of a project and let us bundle components which belong together. We can import this module where we need it instead of declaring all components at the root level. I.e. a AuthModule can take care of all auth related stuff. No need to let the app know what Components this module is using.

在公司中有很多

DevOps希望让您省时省力,并将事情放在一个地方,因此Angular CLI团队引入了工作区-可以包含多个项目。

DevOps want ease of mind and keep things in one place, so the Angular CLI Team introduced workspaces - which can contain more than one project.

然后,共享诸如AuthModule之类的东西就变得容易了。我们建立一个库,并在不同的项目之间共享。不再需要将此代码复制到每个项目的核心文件夹中。

Then sharing things like an AuthModule becomes easy. We make a library of it and share it among the different projects. No need to have this code being copied into the core folder of each project anymore.

此处为原始文本:

Angular 6讨论最少的功能之一是Angular CLI工作区。工作区或Angular CLI工作区使角度开发人员能够在一个工作区中拥有多个项目。这会将您的所有项目置于同一工作空间下。这不仅限于应用程序,还包括角度库。

One of the least talked about features of Angular 6 is Angular CLI Workspaces. Workspaces or Angular CLI Workspaces give angular developers the ability to have more than one project in one workspace. This brings all your projects under the same workspace. This is not limited to applications but also angular libraries.

这使开发人员可以自由地将大型应用程序分解为较小的应用程序和模块。然后,可以使用这些特定模块在应用程序之间共享诸如身份验证模块之类的模块。

This gives developers the freedom of breaking down large applications into smaller applications and modules. The modules such as authentication module can then be shared across the applications using those specific modules. This improves the workflow by reducing code repetition using shared libraries that are generated and managed by Angular CLI.

这很好!通过减少使用Angular CLI生成和管理的共享库的代码重复,可以改善工作流程。谢谢你的回答,有了这个道理。

Great! Thanks for the answer, with this it makes sense.

这篇关于角模块与库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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