用 ng add 安装 Angular UI 库 | ng-hub-ui

ng-hub-ui 家族的安装器:一条 ng add 命令,询问你需要哪些库,解析每个库所需的包,并写入你的清单。

交互式示例

探索实时示例,了解该库在常见 Angular 用例中的表现。

一条命令

`ng add ng-hub-ui` 就是全部安装过程。Angular CLI 拉取该包并运行它的 `ng-add` 原理图,原理图会询问你需要目录中 25 个库里的哪些。空格键选择,`a` 全选切换,`i` 反选;确认后所选内容被解析为 npm 包,写入 `dependencies`,安装交给 CLI 检测到的包管理器完成。

交互式安装

Space selects, a toggles everything and i inverts the selection. The schematic writes the chosen packages into dependencies and then lets the package manager install them.

参数与脚本

交互提示可以跳过,这正是安装器能用于 CI 和项目自身初始化脚本的原因。`--libraries` 接受逗号分隔的列表,也接受重复传入同一个参数,两种写法归一化的结果一致:去空格、去重、保持传入顺序。`--skip-install` 只写清单就停下。请传目录中的标识符,而不是提示里显示的标签——两者是不同的字符串,未知标识符会在 `package.json` 被改动之前中止原理图。

用参数代替提示

Comma-separated

Repeated flag — the same selection, normalized the same way

Manifest only, install left to you

An empty selection fails with Select at least one ng-hub-ui library to install. and an unknown identifier with Unknown ng-hub-ui library: <id>. — in both cases before package.json is touched.

解析后的依赖

选中的清单并不等于写入的清单。目录中的每个库都声明了自己需要的对等依赖——家族里绝大多数需要 `ng-hub-ui-utils`,panels 需要 `ng-hub-ui-ds`,signature 需要 `ng-hub-ui-forms`,还有根本不属于我们的 `sortablejs`——而且解析是传递性的,被一并装上的库还会带来它自己的对等依赖。每个版本范围的下限都不低于家族对它提出的最高要求,这才避免写出 npm 无法满足的组合。已经存在的键永远不会被改写,因此你锁定的版本会保留。原理图只做依赖接线:不动 `angular.json`,不注册提供者,不注册组件,也不添加样式表条目。

这次选择写入了什么

Two libraries asked for…

…five packages written into package.json

The schematic adds a dependency only when the key is absent, so a version already pinned in your manifest survives the install untouched.