Bootstraping OpenUI5 from single JS file

老子叫甜甜 提交于 2019-12-24 16:58:10

问题


OpenUI5 documentation suggests starting work by using a library loaded from CDN:

<script id="sap-ui-bootstrap"
    type="text/javascript"
    src="https://openui5.hana.ondemand.com/1.42.6/resources/sap-ui-core.js"
    data-sap-ui-theme="sap_belize"
    data-sap-ui-libs="sap.m,sap.ui.table"></script>

Unfortunately, this approach means load cascading 4 scripts on startup:

  • sap-ui-core.js
  • sap/ui/core/library.js (why ?)
  • sap/m/library.js
  • sap/ui/table/library.js

Is there way to bundle this four libraries into one script file?


回答1:


Unfortunately, this approach means load cascading multiple scripts on startup:

The cascading behavior is mostly due to missing an option that tells the framework to load UI5-libraries and other modules asynchronously. In order to fix it, please add the following attribute too:

data-sap-ui-async="true" // available since 1.58.2 --> Replaces preload="async"
data-sap-ui-preload="async" // for 1.58.1 and below

Is there way to bundle these four libraries into one script file?

Yes; with a self-contained build, you can reduce the size of your application as well as number of requests by bundling the required modules into a single file sap-ui-custom.js

In the above screenshot, for example, sap-ui-custom.js contains only the required modules from sap.ui.core-, sap.m-, sap.ui.table-, and sap.ui.unified-library, in addition to application related resources such as the controllers, views, etc..

See openui5-sample-app and the UI5 tooling for official documentation.



来源:https://stackoverflow.com/questions/57866410/bootstraping-openui5-from-single-js-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!