2

我有几个组件,我写了一些安装这些组件的示意图。为了可维护性,我的原理图在一个单独的包中。

将我的原理图从 Angular6 合并到 Angular7 后,找不到我的原理图。

所以在我的组件的“package.json”中:

{
  "name": "@my-project/my-component",
  "version": "4.0.0",
  "dependencies": {
    "@my-project/schematics": "^2.0.0",
    "tslib": "^1.9.0"
  },
  "peerDependencies": {
    "@angular/common": "^7.0.0",
    "@angular/core": "^7.0.0"
  },
  "schematics": "./schematics/collection.json",
}

在“./schematics/collection.json”中:

{
  "$schema": "./node_modules/@angular-devkit/schematics/collection-schema.json",
  "schematics": {
    "ng-add": {
      "extends" : "@my-project/schematics:my-component-install"
    }
  }
}

@my-project/schemics 的“collections.json”:

{
  "$schema": "../node_modules/@angular-devkit/schematics/collection-schema.json",
  "schematics": {
      "my-component-install": {
      "description": "Schematics for installation of @my-project/my-component",
      "schema": "./my-component/install/schema.json",
      "factory": "./my-component/install/index"
    }
  }
}

因此,当执行“ng add @my-project/my-component”时,我收到消息:“在集合“@my-project/my-comonent”中找不到示意图“my-component-install”。然而,在 Angular6 中这行得通。

谁能告诉我如何解决这个问题?

4

1 回答 1

1

我对你的结构有点困惑,但我会尽力而为——所以如果你有原理图,让我们说“我的原理图”,它有“ng-add”作为原理图。“我的示意图”扩展了角度示意图,因此它可以做任何角度示意图可以做的事情,但需要额外的逻辑。这就是“我的示意图”的 collection.json 的样子——

{
    “$schema”:.....
    “extends”: [
        “@schematics/angular”
    ],
    “schematics”: {
        “ng-add”: { 
            “description”:.., “factory”:..., “schema”:...
         }
     }
}

现在在您的项目中,您可以调用 my-schematics:ng-add (以及 my-schematics:component 或任何其他角度原理图函数)

于 2018-12-21T20:08:23.330 回答