我们编写了一个自定义库,我们现在想在主应用程序中引用它。 因此,我们将以下两个条目添加到消费者的neo-app.json中:
{
"path": "/webapp/resources/some/lib",
"target": {
"type": "application",
"name": "somedemolib"
},
"description": "..."
}, {
"path": "/resources/some/lib",
"target": {
"type": "application",
"name": "somedemolib"
},
"description": "..."
}
以及libs consumer的manifest.json:
"dependencies": {
"minUI5Version": "1.30.0",
"libs": {
...
"some.lib": {
"minVersion": "1.0.0"
}
}
},
然而,在加载web-app时,我可以在尝试以下路径加载库时看到HTTP404:
Uncaught Error: failed to load 'some/lib/library.js' from ../../resources/some/lib/library.js: 404 - Not Found
答案 0 :(得分:1)
您必须在components.js
的第一行声明自定义脚本首先,您必须声明自定义lib文件夹的路径: https://sapui5.netweaver.ondemand.com/sdk/docs/api/symbols/jQuery.sap.html#.registerModulePath
jQuery.sap.registerResourcePath("libs/custom", "/scripts/customlibs");
在此调用之后,您可以通过此调用从该路径加载脚本:
jQuery.sap.require("libs.custom.nameofyourscript");
“libs.custom”指向您之前注册的文件夹,然后您可以按名称导入脚本。所以你的components.js看起来像这样:
jQuery.sap.registerResourcePath("libs/custom", "/scripts/customlibs");
jQuery.sap.require("libs.custom.nameofyourscript");
// Now the declaration of the components starts
sap.ui.core.UIComponent.extend("yourappname.Component", {
// ...