Last active
October 21, 2024 18:47
-
-
Save matz3/521ab104c48ca24c389d to your computer and use it in GitHub Desktop.
UI5 Custom Bundle Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "ui5-custom-bundle-example", | |
"dependencies": { | |
"openui5-sap.ui.core": "openui5/packaged-sap.ui.core", | |
"openui5-sap.m": "openui5/packaged-sap.m" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = function(grunt) { | |
grunt.initConfig({ | |
copy: { | |
"sap.ui.core": { | |
files: [ | |
{ | |
cwd: "bower_components/openui5-sap.ui.core/resources", | |
src: [ "**/*" ], | |
dots: true, | |
expand: true, | |
dest: "dist/resources/" | |
}, | |
] | |
}, | |
"sap.m": { | |
files: [ | |
{ | |
cwd: "bower_components/openui5-sap.m/resources", | |
src: [ "**/*" ], | |
dots: true, | |
expand: true, | |
dest: "dist/resources/" | |
}, | |
] | |
} | |
}, | |
concat: { | |
"sap-ui-custom.js": { | |
options: { | |
banner: "window['sap-ui-optimized'] = true; ", | |
process: function(src, filepath) { | |
var moduleName = filepath.substr("bower_components/openui5-sap.ui.core/resources/".length); | |
if (moduleName === "sap/ui/thirdparty/jquery-mobile-custom.js") { | |
var preloadName = moduleName.replace(/\//g, ".").replace(/\.js$/, "-preload"); | |
var preload = { | |
"version": "2.0", | |
"name": preloadName, | |
"modules": {} | |
}; | |
preload.modules[moduleName] = src; | |
return "jQuery.sap.registerPreloadedModules(" + JSON.stringify(preload) + ");"; | |
} | |
return src; | |
} | |
}, | |
src: [ | |
"bower_components/openui5-sap.ui.core/resources/sap/ui/thirdparty/jquery.js", | |
"bower_components/openui5-sap.ui.core/resources/sap/ui/thirdparty/jqueryui/jquery-ui-position.js", | |
"bower_components/openui5-sap.ui.core/resources/sap/ui/Device.js", | |
"bower_components/openui5-sap.ui.core/resources/sap/ui/thirdparty/URI.js", | |
"bower_components/openui5-sap.ui.core/resources/jquery.sap.promise.js", | |
"bower_components/openui5-sap.ui.core/resources/jquery.sap.global.js", | |
"bower_components/openui5-sap.ui.core/resources/sap/ui/thirdparty/jquery-mobile-custom.js", | |
"dist/resources/sap-ui-messagebundle-preload.js", | |
"dist/resources/sap/ui/core/custom-library-preload.js" | |
], | |
dest: "dist/resources/sap-ui-custom.js" | |
}, | |
"sap/ui/core/custom-library-preload.js": { | |
options: { | |
banner: "jQuery.sap.registerPreloadedModules(", | |
footer: "); jQuery.sap.require('sap.ui.core.Core'); sap.ui.getCore().boot && sap.ui.getCore().boot();" | |
}, | |
src: "bower_components/openui5-sap.ui.core/resources/sap/ui/core/library-preload.json", | |
dest: "dist/resources/sap/ui/core/custom-library-preload.js" | |
}, | |
"sap-ui-messagebundle-preload.js": { | |
options: { | |
process: function(src, filepath) { | |
var moduleName = filepath.substr(filepath.indexOf("resources/") + "resources/".length); | |
var preloadName = moduleName.replace(/\//g, ".").replace(/\.js$/, "-preload"); | |
var preload = { | |
"version": "2.0", | |
"name": preloadName, | |
"modules": {} | |
}; | |
preload.modules[moduleName] = src; | |
return "jQuery.sap.registerPreloadedModules(" + JSON.stringify(preload) + ");"; | |
} | |
}, | |
src: [ | |
"bower_components/openui5-sap.ui.core/resources/sap/ui/core/*.properties", | |
"bower_components/openui5-sap.m/resources/sap/m/*.properties" | |
], | |
dest: "dist/resources/sap-ui-messagebundle-preload.js" | |
} | |
} | |
}); | |
grunt.loadNpmTasks("grunt-contrib-clean"); | |
grunt.loadNpmTasks("grunt-contrib-copy"); | |
grunt.loadNpmTasks("grunt-contrib-concat"); | |
grunt.registerTask("build", [ | |
"copy", | |
"concat:sap-ui-messagebundle-preload.js", | |
"concat:sap/ui/core/custom-library-preload.js", | |
"concat:sap-ui-custom.js" | |
]); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge" /> | |
<meta charset="UTF-8"> | |
<script id="sap-ui-bootstrap" | |
src="dist/resources/sap-ui-custom.js" | |
data-sap-ui-libs="sap.m" | |
data-sap-ui-theme="sap_hcb" | |
data-sap-ui-bindingSyntax="complex" | |
data-sap-ui-compatVersion="edge" | |
data-sap-ui-preload="async"></script> | |
<script> | |
sap.ui.getCore().attachInit(function() { | |
sap.ui.require(["sap/ui/core/HTML"], function(HTML) { | |
sap.ui.getCore().getLibraryResourceBundle(); | |
// no sync requests! | |
}); | |
}); | |
</script> | |
</head> | |
<body class="sapUiBody"></body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "ui5-custom-bundle-example", | |
"private": true, | |
"scripts": { | |
"build": "bower install && grunt build" | |
}, | |
"devDependencies": { | |
"bower": "^1.5.1", | |
"grunt": "^0.4.5", | |
"grunt-cli": "^0.1.13", | |
"grunt-contrib-concat": "^0.5.1", | |
"grunt-contrib-copy": "^0.8.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is rather a hack than something that should be used in production.
The files might be split up to enable parallel loading via multiple script tags.
Note that the logic is relying on how the
sap-ui-core.js
is built which may change (and also has changed from 1.30 to 1.32, seejquery.sap.promise
=>sap/ui/thirdparty/es-promise
).There’s currently nothing (at least that I know of) to prevent sync library-parameters.json requests.