Angular 模块与库
Angular Module vs. Library
太棒了,Angular 已经发布了版本 6,CLI 提供了一个生成库的选项 - 他们称之为 "highly anticipated feature"。
现在,从商业的角度来看,我想知道:
- 为什么你真的需要这个,
- 为什么在现有项目中而不是单独的项目中,您可以像往常一样通过 npm 安装...
- 如果你想在项目中使用它,为什么不为此使用模块。
所以我明白了,在 npmjs 上发布一些东西,希望整个世界和未来的互联事物都需要它。图书馆,棒棒哒
在一个更大的公司的大系统中,我们可以重用一个库,但我们已经能够重用一个模块的东西。我需要单独构建库并在每次更改内容时重新编译..
使用库而不是模块的原因是什么?
(目前我认为库可以比模块更大,所以我 只是 用它来更好地组织我的应用程序)
在 this website 上我找到了很好的解释。
模块
驻留inside of a project
,让我们捆绑属于一起的组件。我们可以在需要的地方导入这个模块,而不是在根级别声明所有组件。 IE。 AuthModule 可以处理所有与身份验证相关的事情。无需让应用程序知道此模块使用的组件。
图书馆
在企业中有许多不同的应用程序,some/many 将来可能会转向基于 angular。
DevOps 想要轻松自在并将事情放在一个地方,因此 Angular CLI 团队引入了工作区 - 它可以包含多个项目。
然后共享诸如 AuthModule 之类的东西就变得容易了。我们制作了一个库并在不同的项目之间共享。无需再将此代码复制到每个项目的核心文件夹中。
原文在这里:
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.
太棒了!感谢您的回答,有了这个就有意义了。
扩展@hogan 的回答:
它们还提供了一种构建 NPM 包的简单方法,方法是生成一个 "dist" 文件夹,该文件夹将库和 NPM 版本封装在当前开发状态或开发工作区之外。
使用 AngularCLI 创建一个与我们预期的 Angular 库同名的工作区。
--前缀选项,AngularCLI 生成器将自动为正确的库或组件环境使用前缀。
AngularCLI 意识到它需要 "ng-packagr"。它将它添加到我们工作区中的 devDependencies package.json
用法,现在您可以直接从 angularCLI 构建、测试等。
太棒了,Angular 已经发布了版本 6,CLI 提供了一个生成库的选项 - 他们称之为 "highly anticipated feature"。
现在,从商业的角度来看,我想知道:
- 为什么你真的需要这个,
- 为什么在现有项目中而不是单独的项目中,您可以像往常一样通过 npm 安装...
- 如果你想在项目中使用它,为什么不为此使用模块。
所以我明白了,在 npmjs 上发布一些东西,希望整个世界和未来的互联事物都需要它。图书馆,棒棒哒
在一个更大的公司的大系统中,我们可以重用一个库,但我们已经能够重用一个模块的东西。我需要单独构建库并在每次更改内容时重新编译..
使用库而不是模块的原因是什么?
(目前我认为库可以比模块更大,所以我 只是 用它来更好地组织我的应用程序)
在 this website 上我找到了很好的解释。
模块
驻留inside of a project
,让我们捆绑属于一起的组件。我们可以在需要的地方导入这个模块,而不是在根级别声明所有组件。 IE。 AuthModule 可以处理所有与身份验证相关的事情。无需让应用程序知道此模块使用的组件。
图书馆
在企业中有许多不同的应用程序,some/many 将来可能会转向基于 angular。
DevOps 想要轻松自在并将事情放在一个地方,因此 Angular CLI 团队引入了工作区 - 它可以包含多个项目。
然后共享诸如 AuthModule 之类的东西就变得容易了。我们制作了一个库并在不同的项目之间共享。无需再将此代码复制到每个项目的核心文件夹中。
原文在这里:
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.
太棒了!感谢您的回答,有了这个就有意义了。
扩展@hogan 的回答:
它们还提供了一种构建 NPM 包的简单方法,方法是生成一个 "dist" 文件夹,该文件夹将库和 NPM 版本封装在当前开发状态或开发工作区之外。
使用 AngularCLI 创建一个与我们预期的 Angular 库同名的工作区。
--前缀选项,AngularCLI 生成器将自动为正确的库或组件环境使用前缀。
AngularCLI 意识到它需要 "ng-packagr"。它将它添加到我们工作区中的 devDependencies package.json
用法,现在您可以直接从 angularCLI 构建、测试等。