Skip to Content
0
May 08 at 09:51 AM

In a multi-app CAP project, how can I share a frontend class between apps?

228 Views

We have a SAP CAP project with multiple applications. Our folder structure looks similar to this:

- app/
   - admin_app/
      - webapp/controller/
         - handler.js
      - package.json
   - business_app/
   - another_app/
- srv/
   - service.ts
- package.json
- tsconfig.json

There was a lot of repetitive code in the `handler.js` of each app. I already moved the reusable code into a separate "Class" file.

sap.ui.define(
    [
        'sap/m/MessageToast',
        'sap/m/Button',
        'sap/m/ButtonType',
        'sap/m/CheckBox',
        'sap/m/ListMode',
    ],
    function (
        MessageToast,
        Button,
        ButtonType,
        CheckBox,
        ListMode
    ) {
        'use strict';
        return class ReusableClass {
I tried putting the class in the `app` root but the page gives an error about referencing a file outside the app.How do I arrange things so that I can share this in all apps?