|
| 1 | +import semver from "semver"; |
1 | 2 | import {getLogger} from "@ui5/logger"; |
2 | 3 | const log = getLogger("builder:tasks:bundlers:generateLibraryPreload"); |
3 | 4 | import moduleBundler from "../../processors/bundlers/moduleBundler.js"; |
@@ -106,6 +107,63 @@ function getBundleDefinition(namespace, excludes) { |
106 | 107 | }; |
107 | 108 | } |
108 | 109 |
|
| 110 | +function getBundleInfoPreloadDefinition(namespace, excludes, coreVersion) { |
| 111 | + const sections = [{ |
| 112 | + mode: "preload", |
| 113 | + filters: [ |
| 114 | + `${namespace}/library.js`, |
| 115 | + ], |
| 116 | + resolve: true |
| 117 | + }, |
| 118 | + { |
| 119 | + mode: "bundleInfo", |
| 120 | + name: `${namespace}/library-content.js`, |
| 121 | + filters: getDefaultLibraryPreloadFilters(namespace, excludes), |
| 122 | + resolve: false, |
| 123 | + resolveConditional: false, |
| 124 | + renderer: true |
| 125 | + }]; |
| 126 | + |
| 127 | + if (coreVersion) { |
| 128 | + const parsedVersion = semver.parse(coreVersion); |
| 129 | + if (parsedVersion) { |
| 130 | + if (parsedVersion.major >= 2) { |
| 131 | + // Do not include manifest.json in UI5 2.x and higher to allow for loading it upfront for all libraries |
| 132 | + sections.unshift({ |
| 133 | + mode: "provided", |
| 134 | + filters: [ |
| 135 | + `${namespace}/manifest.json`, |
| 136 | + ] |
| 137 | + }); |
| 138 | + } |
| 139 | + } |
| 140 | + } |
| 141 | + |
| 142 | + return { |
| 143 | + name: `${namespace}/library-preload.js`, |
| 144 | + sections, |
| 145 | + }; |
| 146 | +} |
| 147 | + |
| 148 | +function getContentBundleDefinition(namespace, excludes) { |
| 149 | + return { |
| 150 | + name: `${namespace}/library-content.js`, |
| 151 | + sections: [{ |
| 152 | + mode: "provided", |
| 153 | + filters: [ |
| 154 | + `${namespace}/library.js`, |
| 155 | + ], |
| 156 | + resolve: true |
| 157 | + }, { |
| 158 | + mode: "preload", |
| 159 | + filters: getDefaultLibraryPreloadFilters(namespace, excludes), |
| 160 | + resolve: false, |
| 161 | + resolveConditional: false, |
| 162 | + renderer: true |
| 163 | + }] |
| 164 | + }; |
| 165 | +} |
| 166 | + |
109 | 167 | function getDesigntimeBundleDefinition(namespace) { |
110 | 168 | return { |
111 | 169 | name: `${namespace}/designtime/library-preload.designtime.js`, |
@@ -258,6 +316,7 @@ export default async function({workspace, taskUtil, options: {skipBundles = [], |
258 | 316 | } |
259 | 317 | const coreVersion = taskUtil?.getProject("sap.ui.core")?.getVersion(); |
260 | 318 | const allowStringBundling = taskUtil?.getProject().getSpecVersion().lt("4.0"); |
| 319 | + const createBundleInfoPreload = !!process.env.UI5_CLI_EXPERIMENTAL_BUNDLE_INFO_PRELOAD; |
261 | 320 | const execModuleBundlerIfNeeded = ({options, resources}) => { |
262 | 321 | if (skipBundles.includes(options.bundleDefinition.name)) { |
263 | 322 | log.verbose(`Skipping generation of bundle ${options.bundleDefinition.name}`); |
@@ -390,42 +449,98 @@ export default async function({workspace, taskUtil, options: {skipBundles = [], |
390 | 449 | const libraryNamespaceMatch = libraryIndicatorPath.match(libraryNamespacePattern); |
391 | 450 | if (libraryNamespaceMatch && libraryNamespaceMatch[1]) { |
392 | 451 | const libraryNamespace = libraryNamespaceMatch[1]; |
393 | | - const results = await Promise.all([ |
394 | | - execModuleBundlerIfNeeded({ |
395 | | - options: { |
396 | | - bundleDefinition: getBundleDefinition(libraryNamespace, excludes), |
397 | | - bundleOptions: { |
398 | | - optimize: true, |
399 | | - ignoreMissingModules: true |
400 | | - } |
401 | | - }, |
402 | | - resources |
403 | | - }), |
404 | | - execModuleBundlerIfNeeded({ |
405 | | - options: { |
406 | | - bundleDefinition: getDesigntimeBundleDefinition(libraryNamespace), |
407 | | - bundleOptions: { |
408 | | - optimize: true, |
409 | | - ignoreMissingModules: true, |
410 | | - skipIfEmpty: true |
411 | | - } |
412 | | - }, |
413 | | - resources |
414 | | - }), |
415 | | - execModuleBundlerIfNeeded({ |
416 | | - options: { |
417 | | - bundleDefinition: getSupportFilesBundleDefinition(libraryNamespace), |
418 | | - bundleOptions: { |
419 | | - optimize: false, |
420 | | - ignoreMissingModules: true, |
421 | | - skipIfEmpty: true |
422 | | - } |
423 | | - // Note: Although the bundle uses optimize=false, there is |
424 | | - // no moduleNameMapping needed, as support files are excluded from minification. |
425 | | - }, |
426 | | - resources |
427 | | - }) |
428 | | - ]); |
| 452 | + let results; |
| 453 | + if (!createBundleInfoPreload) { |
| 454 | + // Regular bundling |
| 455 | + results = await Promise.all([ |
| 456 | + execModuleBundlerIfNeeded({ |
| 457 | + options: { |
| 458 | + bundleDefinition: getBundleDefinition(libraryNamespace, excludes), |
| 459 | + bundleOptions: { |
| 460 | + optimize: true, |
| 461 | + ignoreMissingModules: true |
| 462 | + } |
| 463 | + }, |
| 464 | + resources |
| 465 | + }), |
| 466 | + execModuleBundlerIfNeeded({ |
| 467 | + options: { |
| 468 | + bundleDefinition: getDesigntimeBundleDefinition(libraryNamespace), |
| 469 | + bundleOptions: { |
| 470 | + optimize: true, |
| 471 | + ignoreMissingModules: true, |
| 472 | + skipIfEmpty: true |
| 473 | + } |
| 474 | + }, |
| 475 | + resources |
| 476 | + }), |
| 477 | + execModuleBundlerIfNeeded({ |
| 478 | + options: { |
| 479 | + bundleDefinition: getSupportFilesBundleDefinition(libraryNamespace), |
| 480 | + bundleOptions: { |
| 481 | + optimize: false, |
| 482 | + ignoreMissingModules: true, |
| 483 | + skipIfEmpty: true |
| 484 | + } |
| 485 | + // Note: Although the bundle uses optimize=false, there is |
| 486 | + // no moduleNameMapping needed, as support files are excluded from minification. |
| 487 | + }, |
| 488 | + resources |
| 489 | + }) |
| 490 | + ]); |
| 491 | + } else { |
| 492 | + log.info( |
| 493 | + `Using experimental bundling with bundle info preload ` + |
| 494 | + `for library ${libraryNamespace} in project ${projectName}.`); |
| 495 | + // Experimental bundling with bundle info preload |
| 496 | + results = await Promise.all([ |
| 497 | + execModuleBundlerIfNeeded({ |
| 498 | + options: { |
| 499 | + bundleDefinition: |
| 500 | + getBundleInfoPreloadDefinition(libraryNamespace, excludes, coreVersion), |
| 501 | + bundleOptions: { |
| 502 | + optimize: true, |
| 503 | + ignoreMissingModules: true |
| 504 | + } |
| 505 | + }, |
| 506 | + resources |
| 507 | + }), |
| 508 | + execModuleBundlerIfNeeded({ |
| 509 | + options: { |
| 510 | + bundleDefinition: getContentBundleDefinition(libraryNamespace, excludes), |
| 511 | + bundleOptions: { |
| 512 | + optimize: true, |
| 513 | + ignoreMissingModules: true |
| 514 | + } |
| 515 | + }, |
| 516 | + resources |
| 517 | + }), |
| 518 | + execModuleBundlerIfNeeded({ |
| 519 | + options: { |
| 520 | + bundleDefinition: getDesigntimeBundleDefinition(libraryNamespace), |
| 521 | + bundleOptions: { |
| 522 | + optimize: true, |
| 523 | + ignoreMissingModules: true, |
| 524 | + skipIfEmpty: true |
| 525 | + } |
| 526 | + }, |
| 527 | + resources |
| 528 | + }), |
| 529 | + execModuleBundlerIfNeeded({ |
| 530 | + options: { |
| 531 | + bundleDefinition: getSupportFilesBundleDefinition(libraryNamespace), |
| 532 | + bundleOptions: { |
| 533 | + optimize: false, |
| 534 | + ignoreMissingModules: true, |
| 535 | + skipIfEmpty: true |
| 536 | + } |
| 537 | + // Note: Although the bundle uses optimize=false, there is |
| 538 | + // no moduleNameMapping needed, as support files are excluded from minification. |
| 539 | + }, |
| 540 | + resources |
| 541 | + }) |
| 542 | + ]); |
| 543 | + } |
429 | 544 | const bundles = Array.prototype.concat.apply([], results).filter(Boolean); |
430 | 545 | return Promise.all(bundles.map(({bundle, sourceMap} = {}) => { |
431 | 546 | if (bundle) { |
|
0 commit comments