Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PoC] Bundle "require" section: Use async require #969

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 16 additions & 9 deletions lib/lbt/bundle/Builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) ||
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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
Expand Down
Loading