问题
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