我有一个项目 Child 有一个添加原理图。如果 Child 成为项目 Parent 的依赖项,该项目也具有添加原理图,那么 ng-cli 将如何处理?我没有看到任何对ng add
级联或调用依赖模式的引用。Parent 是否需要复制 Child 的原理图,或者有没有办法手动调用 Parent 原理图中的 Child 的原理图?
问问题
282 次
1 回答
1
我真的希望文档更好,但解决方案最终是两件事的结合:
首先,您可以像这样调用外部原理图:
externalSchematic('@keysight/alloy', 'ng-add', options)
但是,仅此还不够,因为它无法找到您的包裹。您需要先安装它。这是最终的解决方案:
export function ngAdd(options: any): Rule {
return (tree: Tree, context: SchematicContext) => {
console.log('Adding Pathwave Core dependencies...\n');
dependencies.forEach(dep => addPackageJsonDependency(tree, dep));
const installTaskId = context.addTask(new NodePackageInstallTask());
// Chain won't work here since we need the externals to be actually installed before we call their schemas
// This ensures the externals are a dependency of the node install, so they exist when their schemas run.
context.addTask(new RunSchematicTask('addExternals', options), [installTaskId]);
};
}
export function addExternals(options: any): Rule {
return (_tree: Tree, _context: SchematicContext) => {
console.log('Running dependency schematics...\n');
return chain([
externalSchematic('@keysight/alloy', 'ng-add', options)
]);
};
}
addExternals
必须是它自己的示意图collection.json
:
"addExternals": {
"description": "Calls dependency add schemas",
"private": true,
"factory": "./ng-add/index#addExternals"
}
于 2020-01-21T22:30:45.240 回答