Angular Module vs. Library

主宰稳场 提交于 2019-12-06 07:11:11

On this website I found a great explanation.

Modules

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.

Libraries

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

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.

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.

Here the original text:

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.

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

To extend @hogan answer:

  • They also provide an easy way to build NPM packages by generating a "dist" folder that encapsulates the library and NPM releases away from the current dev state or dev workspace.

  • Uses AngularCLI to create a workspace with the same name as our intended Angular library.

  • --Prefix option, the AngularCLI generator will automatically use prefixes for the right library or component environment.

  • The AngularCLI realizes that it needs "ng-packagr". It adds it to our devDependencies in our workspace package.json

  • Usage, now you can build, test, and more directly from angularCLI.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!