Skip to content

Instantly share code, notes, and snippets.

@docertabum
Forked from matz3/Gruntfile.js
Created April 12, 2021 10:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save docertabum/cb8f790634d227a8613f896bda31b8a4 to your computer and use it in GitHub Desktop.
Save docertabum/cb8f790634d227a8613f896bda31b8a4 to your computer and use it in GitHub Desktop.
UI5 Custom Bundle Example
{
"name": "ui5-custom-bundle-example",
"dependencies": {
"openui5-sap.ui.core": "openui5/packaged-sap.ui.core",
"openui5-sap.m": "openui5/packaged-sap.m"
}
}
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"
]);
};
<!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>
{
"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