Reusing SAPUI5 custom control library in Web IDE

2019-06-14 03:59发布

问题:

It is more or less clear how to implement a SAPUI5 control library and deploy it to SAP ABAP repository, however I am completely lost at attempting to reuse it in Web-IDE. Web-IDE just does not see the library deployed to SAP ABAP repository. Certainly I can always clone the library files into all the projects, but it is not a right methodology. Tried different variants of dependency path to no avail.

Does anyone have a clue?

Thank you.

回答1:

Finally, the problem's been solved. And this is how:

  1. First, in Web IDE I created a separate project for the library

  2. Under the root folder of the project I created another folder named "library" (name can be arbitrary). Under the "library" folder I created folder hierarchy according to the id (or namespace) of the library: suppose you are developing library with the name space "com.your_proud_company_name.controls", in that case you have to create a nested folder hierarchy corresponding to the path "com/your_proud_company_name/controls".

  3. I placed all my library files together with the properly written library.js file into the deepest folder ("controls" in the example)
  4. And now it's time to deploy the new project to the SAP HCP (in the local menu for the project select Deploy -> Deploy to SAP HANA Cloud Platform). When deploying you will be asked for the name of the application. Give an arbitrary name and note it somewhere. We will use it later. Also make note of the version of the deployed application (SAP will provide default number automatically - like 1.0.1)

  5. Now go to your app project where you plan to use this library and open the file neo-app.json

  6. Add the following entry to the "routes" list:

    {

       "path": "/webapp/resources",
       "target": {
           "type": "application",
           "name": "your_deployed_library_application_name", 
           "version": "version_of_your_deployed_library_application",
           "entryPath": "/library"
       },
       "description": "Custom control library"
    

    },

  7. In this "roots" entry "webapp" is the default name of the root folder of the app, if you are using some other name change the "path" value accordingly

  8. "type" value ("application" in our case) is one of the predefined types fo routes and is used for shareable applications.

  9. "name" value is the name of the deployed application (not the name of the project in Web IDE).

  10. "entryPath" value is the root folder in the library project (and application) where the HCP starts searching for library files.

  11. Now you can add the library as a dependency to the manifest.json file of your app project. The entry under "dependencies" should look like this (put your specific value into "minVersion"):

        "com.your_proud_company_name.controls": {
            "minVersion": "1.0.5"
        }
    


回答2:

Have you tried to setup the dependency in the manifest.json file ? Never tried your setup, but just a hint.

"dependencies": {
            "minUI5Version": "1.38.0",
            "libs": {
                "sap.ui.core": {},
                "sap.m": {},
                "sap.ui.layout": {},
                "YOUR_LIB": {}
            }