Jerry's previous article Angular schematic Schematics learning-hands-on development of a practical example , has developed a working Angular library Schematics.
This article introduces the specific operation steps.
In the root directory of the workspace, run the ng build command of the library.
ng build my-lib
Ensure that the build passes:
If you encounter an error, you can refer to the code my code repository.
And this article: Solution to the error of library Schematics build downloaded from Angular official website
Then, enter the library directory and build the schematic
cd projects/my-lib
npm run build
Ensure that the command runs successfully.
Link this library
These libraries and schematics have been packaged and placed in the dist/my-lib folder in the root directory of your workspace.
To run this schematic, you need to link this library into the node_modules folder. In the root directory of the workspace, run the npm link command and use the path of your distributable library as a parameter.
After execution:
I found that my own library also appeared under the node_modules folder in the root directory of the workspace:
At the same time, there is also a shortcut in the node_modules folder of my Node.js installation directory:
Finally, you can finally start to run the schematic.
Run the command line:
ng generate my-lib:my-service --name my-data
The name parameter value passed in is my-data.
The result printed from the command line shows that my-data.service.ts has been created successfully:
The contents of the file are as follows:
Compare the template files in our Schematics:
This example will be executed successfully.
More original articles by Jerry, all in: "Wang Zixi":
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。