简体   繁体   English

在另一个项目中使用SAPUI5库

[英]Using a SAPUI5 library in another project

I am currently trying to understand UI5 libraries and, for the purposes of testing, created a library project from the template that is provided in the Full-Stack-IDE. 我目前正在尝试了解UI5库,并且出于测试目的,使用Full-Stack-IDE中提供的模板创建了一个库项目。

From what I saw in various tutorials, you should now deploy the app to the SCP and then declare its existence to the app where you are going to use it. 根据我在各种教程中看到的内容,现在应该将应用程序部署到SCP,然后在要使用它的应用程序中声明其存在。 You do this by creating an entry in the neo-app.json like so: 为此,您可以在neo-app.json中创建一个条目,如下所示:

"routes": [
    ...,
    {
        "path": "/resources/my/custom",
        "target": {
            "type": "application",
            "name": "testlibrary",
            "entryPath": "/"
        },
        "description": "Utility library"
    }
]

and in the manifest.json like so: 并在manifest.json中像这样:

"dependencies": {
    "libs": {
        ...,
        "my.custom.testlibrary": {}
    }
},

However, when I do this, my app tries to look for the library under this url: https://openui5.hana.ondemand.com/1.52.5/resources/ and not on the SCP where I deployed the app. 但是,当我这样做时,我的应用程序尝试在以下URL下查找该库: https : //openui5.hana.ondemand.com/1.52.5/resources/,而不是在我部署该应用程序的SCP上。 There seems to be no link between my neo-app.json entry and my manifest.json entry. 我的neo-app.json条目和manifest.json条目之间似乎没有链接。 What am I doing wrong here? 我在这里做错了什么?

You can add your custom library by right-clicking on your project, and selecting Project > Add Reference to Library . 您可以通过右键单击您的项目,然后选择Project> Add Reference to Library来添加定制库。 Then select SAP Cloud Platform as repository, and include your library. 然后选择SAP Cloud Platform作为存储库,并包含您的库。

The resulting path in the route in neo-app.json , will be /webapp/resources/my/custom - this is required for running local previews in SAP Web IDE. neo-app.json route的结果path/webapp/resources/my/custom neo-app.json这是在SAP Web IDE中运行本地预览所必需的。 As part of the build process when deploying your consumer app to SAP Cloud Platform, this route will be rewritten to exclude webapp , ie the path will be /resources/my/custom , so that it will also redirect correctly when deployed. 在将消费者应用程序部署到SAP Cloud Platform时,作为构建过程的一部分,该路由将被重写为排除webapp ,即路径将为/resources/my/custom ,以便在部署时也将正确重定向。 This is working for me using "@sap/grunt-sapui5-bestpractice-build": "1.3.64" for the build. 这对我来说使用"@sap/grunt-sapui5-bestpractice-build": "1.3.64"来为我工作。

Using the above, you don't need to add a data-sap-ui-resourceroots entry per library in your consumer app's index.html . 使用上面的方法,您不需要在消费者应用程序的index.html每个库添加data-sap-ui-resourceroots条目。

Found the answer in the ui5help Slack channel. 在ui5help Slack频道中找到了答案。 The issue was that my library needed to be declared in my index.html under resourceroots. 问题是我的库需要在resourceroots下的index.html中声明。 Changing my neo-app.json like so: 像这样更改我的neo-app.json:

"routes": [
    ...,
    {
        "path": "/webapp/resources/my/custom",
        "target": {
            "type": "application",
            "name": "testlibrary",
            "entryPath": "/"
        },
        "description": "Utility library"
    }
]

and adding this to my index.html: 并将其添加到我的index.html中:

data-sap-ui-resourceroots='{
    "docgen": "./",
    "my.custom.testlibrary": "./resources/my/custom"
}'

fixed the problem. 解决了问题。 I will keep experimenting to see if I have to do this for every library. 我将继续尝试看看是否必须为每个库执行此操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM