From a85d35503ad1dc727d0ba3d03e616c538b6430d0 Mon Sep 17 00:00:00 2001 From: Sven Bender Date: Fri, 1 Oct 2021 15:20:39 +0200 Subject: [PATCH] [FEATURE] Enable async loading via async attribute of bootstrap script tag --- lib/lbt/bundle/Builder.js | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/lib/lbt/bundle/Builder.js b/lib/lbt/bundle/Builder.js index 1e6c4f17f..b1bd67903 100644 --- a/lib/lbt/bundle/Builder.js +++ b/lib/lbt/bundle/Builder.js @@ -66,6 +66,10 @@ const UI5BundleFormat = { outW.writeln(`sap.ui.requireSync("${ModuleName.toRequireJSName(moduleName)}");`); }, + bootCore(outW) { + outW.writeln("sap.ui.requireSync(\"sap/ui/core/Core\").boot();"); + }, + shouldDecorate(resolvedModule) { return resolvedModule.executes(UI5ClientConstants.MODULE__JQUERY_SAP_GLOBAL); } @@ -96,6 +100,14 @@ const EVOBundleFormat = { outW.writeln(`sap.ui.requireSync("${ModuleName.toRequireJSName(moduleName)}");`); }, + bootCore(outW) { + outW.writeln("if (sap.ui.loader.bootAsync) {"); + outW.writeln(" sap.ui.require([\"sap/ui/core/Core\"],function(oCore){oCore.boot();});"); + outW.writeln("} else {"); + outW.writeln(" sap.ui.requireSync(\"sap/ui/core/Core\").boot();"); + outW.writeln("}"); + }, + shouldDecorate(resolvedModule) { return resolvedModule.executes(UI5ClientConstants.MODULE__UI5LOADER) || resolvedModule.executes(UI5ClientConstants.MODULE__UI5LOADER_AUTOCONFIG) || @@ -202,11 +214,13 @@ class BundleBuilder { } closeModule(resolvedModule) { + /* TODO: is this still required? This seems to be redundant + because the core is already booted when the requires are added. if ( resolvedModule.containsCore ) { this.outW.ensureNewLine(); // for clarity and to avoid issues with single line comments this.outW.writeln(`// as this module contains the Core, we ensure that the Core has been booted`); this.outW.writeln(`sap.ui.getCore().boot && sap.ui.getCore().boot();`); - } + }*/ if ( this.shouldDecorate && this.options.addTryCatchRestartWrapper ) { this.outW.ensureNewLine(); // for clarity and to avoid issues with single line comments this.outW.writeln(`} catch(oError) {`); @@ -495,9 +509,13 @@ class BundleBuilder { writeRequires(section) { this.outW.ensureNewLine(); - section.modules.forEach( (module) => { - this.targetBundleFormat.requireSync(this.outW, module); - }); + if (section.modules.length === 1 && section.modules.includes(UI5ClientConstants.MODULE__SAP_UI_CORE_CORE)) { + this.targetBundleFormat.bootCore(this.outW); + } else { + section.modules.forEach((module) => { + this.targetBundleFormat.requireSync(this.outW, module); + }); + } } }