【问题标题】:Nested Angular add schematics嵌套 Angular 添加原理图
【发布时间】:2020-05-07 15:11:39
【问题描述】:

我有一个具有添加原理图的子项目。如果 Child 成为项目 Parent 的依赖项,该项目也具有添加原理图,那么 ng-cli 将如何处理?我没有看到对ng add 的任何引用级联或调用依赖模式。 Parent 是否需要复制 Child 的原理图,或者有没有办法在 Parent 原理图中手动调用 Child 的原理图?

【问题讨论】:

    标签: angular angular-schematics


    【解决方案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"
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-08-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-12-12
      • 2019-12-13
      • 1970-01-01
      相关资源
      最近更新 更多