From 693bcca3d02d30b0e8a254ec77279d46df8780a4 Mon Sep 17 00:00:00 2001 From: Matthias Osswald Date: Thu, 21 Dec 2023 14:04:56 +0100 Subject: [PATCH] [PoC] Bundle "require" section: Use async require --- lib/lbt/bundle/Builder.js | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/lib/lbt/bundle/Builder.js b/lib/lbt/bundle/Builder.js index 71a839fb9..9877888eb 100644 --- a/lib/lbt/bundle/Builder.js +++ b/lib/lbt/bundle/Builder.js @@ -66,6 +66,19 @@ const EVOBundleFormat = { return `sap.ui.requireSync("${toRequireJSName(moduleName)}");\n`; }, + require(modules) { + let requireCallback = ""; + const coreModuleIndex = modules.indexOf(MODULE__SAP_UI_CORE_CORE); + if (coreModuleIndex != -1) { + requireCallback = `, (${ + modules.map((m, i) => i === coreModuleIndex ? `Core` : `_m${i}`) + }) => { Core.boot() }`; + } + return `sap.ui.require([${ + modules.map(($) => `"${toRequireJSName($)}"`).join(",\n") + }]${requireCallback});\n`; + }, + shouldDecorate(resolvedModule) { return resolvedModule.executes(MODULE__UI5LOADER) || resolvedModule.executes(MODULE__UI5LOADER_AUTOCONFIG) || @@ -195,12 +208,6 @@ class BundleBuilder { } closeModule(resolvedModule) { - if ( resolvedModule.containsCore ) { - this.outW.ensureNewLine(); // for clarity and to avoid issues with single line comments - this.writeWithSourceMap( - `// as this module contains the Core, we ensure that the Core has been booted\n` + - `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.writeWithSourceMap( @@ -554,9 +561,9 @@ class BundleBuilder { writeRequires(section) { this.outW.ensureNewLine(); - section.modules.forEach( (module) => { - this.writeWithSourceMap(this.targetBundleFormat.requireSync(module)); - }); + if (section.modules.length > 0) { + this.writeWithSourceMap(this.targetBundleFormat.require(section.modules)); + } } // When AutoSplit is enabled for depCache, we need to ensure that modules