Skip to content

Commit

Permalink
depCache for LibraryPreload task
Browse files Browse the repository at this point in the history
  • Loading branch information
d3xter666 committed Nov 1, 2023
1 parent 1d97d68 commit 0642eb1
Showing 1 changed file with 73 additions and 53 deletions.
126 changes: 73 additions & 53 deletions lib/tasks/bundlers/generateLibraryPreload.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,63 @@ function getDefaultLibraryPreloadFilters(namespace, excludes) {
return filters;
}

function getBundleDefinition(namespace, excludes) {
function getBundleDefinition(namespace, excludes, preloadMode = "preload") {
const preloadBundleSuffix = preloadMode === "preload" ? "preload" : "depcache-preload";
let preloadDef;
let depCachePreloadDef;
// TODO: move to config of actual core project
if (namespace === "sap/ui/core") {
preloadDef = {
mode: "preload",
filters: [
// Note: Don't pass configured preload excludes for sap.ui.core
// as they are already hardcoded below.
// In future the sap/ui/core/library-preload should be configured
// as a custom bundle in the ui5.yaml.
...getDefaultLibraryPreloadFilters(namespace),

`!${namespace}/cldr/`,
"*.js",
"sap/base/",
"sap/ui/base/",
"sap/ui/dom/",
"sap/ui/events/",
"sap/ui/model/",
"sap/ui/security/",
"sap/ui/util/",
"sap/ui/Global.js",

// include only thirdparty that is very likely to be used
"sap/ui/thirdparty/crossroads.js",
"sap/ui/thirdparty/caja-html-sanitizer.js",
"sap/ui/thirdparty/hasher.js",
"sap/ui/thirdparty/signals.js",
"sap/ui/thirdparty/jquery-mobile-custom.js",
"sap/ui/thirdparty/jqueryui/jquery-ui-core.js",
"sap/ui/thirdparty/jqueryui/jquery-ui-position.js",

// other excludes (not required for productive scenarios)
"!sap-ui-*.js",
"!sap/ui/core/support/",
"!sap/ui/core/plugin/DeclarativeSupport.js",
"!sap/ui/core/plugin/LessSupport.js"

],
resolve: false,
resolveConditional: false,
renderer: true
};

// TODO: Adjust filters
if (preloadMode === "depCache") {
depCachePreloadDef = {
...preloadDef,
...{mode: "depCache"}
};
}

return {
name: `${namespace}/library-preload.js`,
name: `${namespace}/library-${preloadBundleSuffix}.js`,
sections: [
{
// exclude the content of sap-ui-core by declaring it as 'provided'
Expand All @@ -46,60 +98,28 @@ function getBundleDefinition(namespace, excludes) {
],
resolve: true
},
{
mode: "preload",
filters: [
// Note: Don't pass configured preload excludes for sap.ui.core
// as they are already hardcoded below.
// In future the sap/ui/core/library-preload should be configured
// as a custom bundle in the ui5.yaml.
...getDefaultLibraryPreloadFilters(namespace),

`!${namespace}/cldr/`,
"*.js",
"sap/base/",
"sap/ui/base/",
"sap/ui/dom/",
"sap/ui/events/",
"sap/ui/model/",
"sap/ui/security/",
"sap/ui/util/",
"sap/ui/Global.js",

// include only thirdparty that is very likely to be used
"sap/ui/thirdparty/crossroads.js",
"sap/ui/thirdparty/caja-html-sanitizer.js",
"sap/ui/thirdparty/hasher.js",
"sap/ui/thirdparty/signals.js",
"sap/ui/thirdparty/jquery-mobile-custom.js",
"sap/ui/thirdparty/jqueryui/jquery-ui-core.js",
"sap/ui/thirdparty/jqueryui/jquery-ui-position.js",

// other excludes (not required for productive scenarios)
"!sap-ui-*.js",
"!sap/ui/core/support/",
"!sap/ui/core/plugin/DeclarativeSupport.js",
"!sap/ui/core/plugin/LessSupport.js"

],
resolve: false,
resolveConditional: false,
renderer: true
}
preloadDef,
...[depCachePreloadDef]
]
};
}

preloadDef = {
mode: "preload",
filters: getDefaultLibraryPreloadFilters(namespace, excludes),
resolve: false,
resolveConditional: false,
renderer: true
};

// TODO: Adjust filters
if (preloadMode === "depCache") {
depCachePreloadDef = {...preloadDef, ...{mode: "depCache"}};
}

return {
name: `${namespace}/library-preload.js`,
sections: [
{
mode: "preload",
filters: getDefaultLibraryPreloadFilters(namespace, excludes),
resolve: false,
resolveConditional: false,
renderer: true
}
]
name: `${namespace}/library-${preloadBundleSuffix}.js`,
sections: [preloadDef, ...[depCachePreloadDef]],
};
}

Expand Down Expand Up @@ -385,7 +405,7 @@ export default async function({workspace, taskUtil, options: {skipBundles = [],
const results = await Promise.all([
execModuleBundlerIfNeeded({
options: {
bundleDefinition: getBundleDefinition(libraryNamespace, excludes),
bundleDefinition: getBundleDefinition(libraryNamespace, excludes, "depCache"),
bundleOptions: {
optimize: true,
usePredefineCalls: true,
Expand Down

0 comments on commit 0642eb1

Please sign in to comment.