We are about to close a SAPUI5 application, one of the last steps is to make a Component-Preload.js
file to improve performance. I read different guides around the web, all of them need Node.js that I have installed. I'm not expert about that package and I can't figure how to make one of that guides work. I'm developing with NetBeans. As far as I see there is not an official tool (am I right?) to generate that file. Can someone with more experience than me suggest a working, well-explained guide to perform that task?
There are several main ways of doing it.
You can use SAP Web IDE to generate it. This assumes that you are using WebIDE to develop your application (which is not true based on your question). The regular version of WebIDE generates this file during the "client build" just before application deployment.
The "multi cloud" version of WebIDE can use a grunt build to do it. You can find more info here if you are interested: https://www.sap.com/developer/tutorials/webide-grunt-basic.html.
Use the new UI5 command line tools (https://npmjs.com/package/@ui5/cli):
npm i -g @ui5/cli
to install the tools globally.ui5 build preload
to build the preload.Use the @sap/grunt-sapui5-bestpractice-build
pre-configured grunt tasks. The downside is that they are more-or-less black boxes which do not allow that much customisation. You can find an example setup on SAP's GitHub repository jenkins-pipelines. In a nutshell:
.npmrc
file which adds the @sap npm registry: @sap:registry=https://npm.sap.com
.npm init
command such that you generate a package.json
file. This file describes your application and your dependencies (runtime dependencies and dev dependencies; you will only have dev dependencies for now, as you just want to build your app). Make sure to mark the package as private. See the npm docu (at the end of the license chapter).npm i grunt -D
and npm i @sap/grunt-sapui5-bestpractice-build -D
.grunt
):module.exports = function (grunt) {
'use strict';
grunt.loadNpmTasks('@sap/grunt-sapui5-bestpractice-build');
grunt.registerTask('default', [
'lint',
'clean',
'build'
]);
};
You can use the official grunt_openui5
plugin to generate the preload file(s). In order to be able to do this, you need to have node installed:
npm init
).npm install grunt-cli --save-dev
.npm install grunt-openui5 --save-dev
.grunt <task_name>
in the console. If you registered your build task as the grunt default task (like in the sample file: grunt.registerTask('default', [...]);
) then you just have to write grunt
. grunt
) inside your IDE as an external tool.gulp-openui5
tool to generate it. I would not recommend this if you are not already using gulp for your builds (as it is not a tool built by SAP). The procedure is the same, but using gulp for building the app instead of grunt (so you need to install node, npm init, install gulp, create the Gulpfile, etc). Note that for most of the above methods, you need nodejs, which you can download and install from here: https://nodejs.org/en/download/.