Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
924 views
in Technique[技术] by (71.8m points)

sapui5 - Adding a custom library as a dependency in SAP Fiori

I have a custom library com.foo.library I would like to include as a dependency of a Fiori-like app I have built.

SAP Fiori Launchpad for Developers -> Best Practices for Launchpad Apps

Declare configuration information, like the location of icons, and library dependencies in the component.js configuration file

makes sense, adding my library as a dependency would look like

    dependencies: {
        libs: ["sap.m", "sap.ui.layout", "com.foo.library"],
        components: []
    },

with Fiori you have the constraint that you must use relative paths.

eg for my dependency to work it must be found at

/resources/com/foo/library

What are the steps for uploading a custom library into the ABAP SAPUI5 Repository and having it served with a relative path?

EDIT:

Currently i have the library loaded on Component.init using

 sap.ui.getCore().loadLibrary("com.foo.library", "absolute path to library");

it works, however I want to set the library as a dependency

ComponentMetadata.prototype._loadDependencies = function() {
..
            if (aLibraries) {
            jQuery.each(aLibraries, function(i, sLib) {
                jQuery.sap.log.info("Component "" + that.getName() + 
                sap.ui.getCore().loadLibrary(sLib);
            });
        }

from code above I can see there is no option to pass in a url when the component loads the library dependencies, so i am assuming that the library has to be found relative to the resources

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

In your Fiori App:

  1. Put your dependencie into the app descriptor (manifest.json) (or if no app descriptor used into the config inside the Component.js)

    dependencies: {
        libs: ["sap.m", "sap.ui.layout", "com.foo.library"],
        components: [com.foo.component]
    }
    
  2. Let sap.ui.core know where to search for the namespace of your library.(Top of your Component.js)

    jQuery.sap.registerModulePath("com.foo", "/Path/on/the/server/");
    

And now you can use your dependencies. And here is why:

Before a module is loaded, the longest registered prefix of its module name is searched for and the associated URL prefix is used as a prefix for the request URL. The remainder of the module name is attached to the request URL by replacing dots ('.') with slashes ('/').

The registration and search operates on full name segments only.

Source: SAP UI5 API Documentation


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...