A CAP plugin allows you to extend the framework with your own features without touching the core framework. This offers the great possibility to create something generic and share it with the community so other developers can benefit from it.
SAP already provides several plugins listed here: https://cap.cloud.sap/docs/plugins/
But also the SAP community is creating and sharing plugins which you can find on npm: https://www.npmjs.com/search?q=cap%20plugin and on Best of CAP: https://bestofcapjs.org/
It is super easy to create your own CAP plugin. Just follow these steps:
"peerDependencies": {
"@sap/cds": ">=8"
},
Before publishing the plugin you need to test this first. This can be done locally by following these steps:
You can choose to create a plugin in JS or TS. In case of TS, additional configuration is required:
Install the following devdependencies in the CAP plugin
npm i -D @types/node
npm i -D typescript
Before making this available to npm, you have to build TS to JS. Therefore, you have to foresee a build command: “tsc” https://github.com/lemaiwo/cds-plugin-handlers/blob/39300bb3e6e154ba8eac6f709479325cf9cf7fb9/package...
To be able to run this, you also need a tsonfig file in your project:
https://github.com/lemaiwo/cds-plugin-handlers/blob/main/tsconfig.json
Once the plugin is ready you can make it available to the SAP Community by publishing this to npm.
Run “npm publish” locally or configure GitHub Actions to automatically publish a new version for every release:
Once published, you can simple use it as an npm dependency and start using it in your project.
It might help you to learn how to create a plugin and about the possibilities by looking in already created plugins. Some examples I made or still working on:
This can help you to learn about the possibilities. What helps me a lot are the examples of SAP: https://cap.cloud.sap/docs/plugins . Each plugin can be found on GitHub here: https://github.com/cap-js .
Also CAP plugins of other community members can help you. You can find them on npm and on best of CAP.
If you have anything that can be reused across CAP projects, turn it into a plugin and share it with the community on npm! Once it is on npm, add it to best of CAP: https://bestofcapjs.org/
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 27 | |
| 24 | |
| 21 | |
| 20 | |
| 14 | |
| 13 | |
| 13 | |
| 12 | |
| 12 | |
| 11 |