通过 angular-cli 生成的角度组件的自定义项目级模板 [英] Custom project-level templates for angular components generated via angular-cli

查看:18
本文介绍了通过 angular-cli 生成的角度组件的自定义项目级模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将自定义角度组件原理图添加到现有项目中?

How do I add custom angular component schematics to existing project?

我想要例如my-page 组件模板将复制现有的 \node_modules\@schematics\angular\component\ 文件,但带有编辑过的模板.

I would like to have e.g. my-page component templates that will replicate existing \node_modules\@schematics\angular\component\ files but with edited templates.

我希望它可以通过 angular-cli 实现,例如ng g my-page pagename 带有原理图属性的命令.

I expect it to be achievable through angular-cli e.g. ng g my-page pagename command with schematics attribute.

目前我修改了 \node_modules\ 下现有 angular 原理图的代码,所以这对我来说很好用(直到下一次安装包),但我想与团队分享这个,这样每个人都将使用预定义的模板将存储在例如src\team-schematics\.

Currently I modified code for existing angular's schematics under \node_modules\ so this works fine for me (until next package installation) but I would like to share this with the team so everyone will use predefined templates that will be stored in e.g. src\team-schematics\.

我如何实现这一目标?

我尝试通过 schematics diagram --name my-schematic 创建新原理图,将角度原理图复制到 \ClientApp\src\app\my-schematic\\ 和尝试启动 $ ng generate my-page --collection \ClientApp\src\app\my-schematic 但到目前为止没有运气:

I tried to create new schematic via schematics schematic --name my-schematic, copied angular schematic into \ClientApp\src\app\my-schematic\\ and trying to launch $ ng generate my-page --collection \ClientApp\src\app\my-schematic but no luck as of now:

错误:找不到模块\\ClientApp\\src\\app\\my-schematic\\";来自 "C:\\Users\\xxx\\Projects\\yyy

推荐答案

您不应修改核心原理图.另一方面,您可以创建自己的原理图.

You shouldn't modify core schematics. On the other hand, you can create your own schematic.

创建原理图是一个循序渐进的过程.您可以在 Schematics — 简介中找到相同的内容.

Creating the schematic is a step-by-step process. You can find the same at Schematics — An Introduction.

这篇关于通过 angular-cli 生成的角度组件的自定义项目级模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆