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

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

问题描述

太好了,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 安装...
  • 如果你想在你的项目中使用它,为什么不为此使用一个模块.

所以我明白了,在 npmjs 上发布一些东西,并希望整个世界和未来的互联事物都需要这样.图书馆,很棒.

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

在更大公司的大系统中,我们可以重用一个库,但我们已经能够重用带有模块的东西.我需要单独构建 lib 并在每次更改某些内容时重新编译..

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 可能比模块更大,所以我只是用它来更好地组织我的应用程序)

(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 这个网站 我找到了一个很好的解释.

On this website I found a great explanation.

驻留在项目内部,让我们捆绑属于一起的组件.我们可以在需要的地方导入这个模块,而不是在根级别声明所有组件.IE.AuthModule 可以处理所有与身份验证相关的事情.无需让应用知道此模块正在使用哪些组件.

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.

在公司中,有许多不同的应用程序,有些/许多应用程序将来可能会转向基于 angular.

In corporations there are many different applications and some/many might move to be based on angular in the future.

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 工作区使 Angular 开发人员能够在一个工作区中拥有多个项目.这会将您的所有项目置于同一个工作区下.这不仅限于应用程序,还包括 Angular 库.

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.

这让开发人员可以自由地将大型应用程序分解为更小的应用程序和模块.然后可以在使用这些特定模块的应用程序之间共享诸如身份验证模块之类的模块.这通过使用由 Angular CLI 生成和管理的共享库减少代码重复来改进工作流程.

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.

太好了!谢谢你的回答,这个是有道理的.

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

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

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