问题
How do I add custom angular component schematics to existing project?
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.
I expect it to be achievable through angular-cli
e.g. ng g my-page pagename
command with schematics attribute.
Currently I modified code for existing agular'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\
.
How do I achieve this?
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:
Error: Could not find module "\\ClientApp\\src\\app\\my-schematic\\" from "C:\\Users\\xxx\\Projects\\yyy
回答1:
You shouldn't modify core schematics. On the other hand, you can create your own schematic.
Creating the schematic is a step-by-step process. You can find the same at Schematics — An Introduction.
回答2:
As for as Angular CLI we can only have one Schematics. Might be you can create custom schmatics '@foo/schematics' and extends the @angular/schematics in angular.json and customize the schematics based on your needs.
ng new C myComponent --collection=@foo/schematics
来源:https://stackoverflow.com/questions/52254130/custom-project-level-templates-for-angular-components-generated-via-angular-cli