Skip to content

Instantly share code, notes, and snippets.

@jasper07
Created July 17, 2014 01:48
Show Gist options
  • Save jasper07/73617e14ad21192d37b4 to your computer and use it in GitHub Desktop.
Save jasper07/73617e14ad21192d37b4 to your computer and use it in GitHub Desktop.
build a component-preload.js using gulp
component-preload.js looks like
jQuery.sap.registerPreloadedModules({
"name": "<myApp>Component-preload",
"version": "X.X",
"modules": <minfied module content as kvp>
});
step 1. recursively minify all the apps modules you want to pre load, Instead of writing them to file write them into javascript object
in gulp would be something like this for your views
var sMyAppName = "testapp";
var sFilename = 'Component-preload'
var oComp = {
name: sMyAppName + "/" + sFilename , //testapp.component-preload
version: "X.X",
modules:{}
};
//minify the views and use tap to write to the javascript object
gulp.src('./views/*.xml')
.pipe(minifyHTML({comments:true}))
.pipe(tap(function(file, t) {
var fPath = path.relative(file.cwd, file.path);
var aPaths = fPath.split(path.sep);
aPaths[0] = sMyAppName;
fPath = aPaths.join('/');
oComp.modules[fPath] = file._contents.toString();
}))
result
oComp.modules["testapp.details.view.xml"] = "<?xml version="1.0" encoding="UTF-8" ?><mvc:view."
do the same for the js files
oComp.modules["testapp.details.controller.js"] = "sap.ui.controller("testapp.view.Detail",{ .."
2. now build the file
var sFileTmp = 'jQuery.sap.registerPreloadedModules(' + JSON.stringify(oComp) + ')';
then you can use fs to save to disc
var sFileNameQ = sFilename + '.js'; //Component-preload.js
fs.writeFile( sFileNameQ ', sFileTmp, function(err) {
if (err) throw err;
console.log('It\'s saved!');
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment