在 Angular 6.0 之前,我已经创建了一些示意图。我在 Angular 5.x 中执行的相同步骤现在总是在我尝试在托管应用程序(的 Angular 6)?.
我的设置(全局 Angular 东西):
Angular CLI: 6.0.0
Node: 8.11.1
OS: win32 x64
@angular-devkit/{architect, core, schematics} 0.6.0
@schematics/angular 0.6.0
rxjs 6.1.0
typescript 2.7.2
我的步骤:
- 运行
schematics schematic --name=my-first-schematics
。因此它创建了一个新的原理图项目,其中包含三个示例架构。然后我导航到那个新文件夹cd my-first-schematics
。 - 运行
npm run build
。它构建无误。 - 运行
schematics .:my-first-schematics
。结果:错误"my-first-schematics"not found in collection "."
我在一些博客中看到,他们执行此步骤时没有出现问题。我从来没有运行过这个命令,我不确定它到底做了什么,所以我会假设这个命令毕竟不是必需的。 - 运行
npm link
以便我可以在新项目中使用这个新的原理图集合。 - 在另一个提示窗口中,我创建了一个新应用程序:
ng new schematics-consumer
,然后在安装 npm 之后,cd schematics-consumer
。 - 运行
npm link my-first-schematics
所以我现在可以访问该原理图库。 - 我导航到
src/app
,因为这是我要生成文件的地方。 - 运行
ng g my-schematic -c my-first-schematics
。导致错误在集合“@schematics/angular”中找不到示意图“my-schematic”
。我指定了一个集合。为什么它没有看到我的新收藏,它仍然认为每个原理图都在@schematics/angular
中?
所以,我不能用原理图生成任何东西。 schematics schematic name=my-first-schematics
生成的默认代码我没有修改任何内容。
是否有一套新的命令、程序等来创建我们自己的自定义原理图?我缺少哪些步骤?我还需要安装什么?如有必要,我会提供更多信息。
目前,还没有关于原理图的新指南或博客,因为 6.0 才推出几周,所以我认为旧方法应该仍然有效。
最佳答案
问题似乎最终出在 angular-cli
上,参见讨论:https://github.com/angular/devkit/issues/528#issuecomment-387415646
要解决这个问题,您可以将默认集合设置为您的自定义原理图:
ng config cli.defaultCollection my-first-schematics
现在您应该能够运行 ng g my-schematic
。
如果这不起作用,您可以发布您的 my-first-schematics
目录的文件列表吗?
关于angular - Angular/CLI 6.x 中的自定义原理图构建没有错误,但我无法使用它来生成文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50534711/