ui5-tooling icon indicating copy to clipboard operation
ui5-tooling copied to clipboard

self-contained build contains unused modules

Open BenReim opened this issue 4 years ago • 2 comments

Expected Behavior

One reason why UI5 modules can be included in the self-contained bundle - even when not explicitly used within the project - is that these modules might be required as dependencies within the ui5 framework itself.

However generally, it is not expected that ui5 classes are part of the self-contained bundle when they are not required anywhere in the project.

Current Behavior

The self-contained bundle contains lots of classes / ui5 controls, even though they aren't included anywhere in the project. For instance in case of the ui5-sample-app:

  • sap/m/Dialog.js
  • sap/m/Select.js
  • sap/m/Table.js

Steps to Reproduce the Issue

  1. git clone https://github.com/SAP/openui5-sample-app.git
  2. cd openui5-sample-app && npm run build-self-contained
  3. Analyze dist/resources/sap-ui-custom.js

Context

  • UI5 Module Version (output of ui5 --version when using the CLI): 2.11.2

BenReim avatar Jun 25 '21 12:06 BenReim

The self-contained bundle is created by analyzing the application code and following eager and conditional dependencies to ensure that all modules required by the application are bundled and available. This means that some modules are bundled while they are not directly used by the application.

Due to the nature of some controls, especially in the sap.m library, this can be confusing and is indeed causing more dependencies to be included than actually needed. sap/m/Input can show suggestions, which are rendered via sap/m/Table, thus it is included in the bundle. sap/m/Dialog is probably included via the sap/m/Support module, which allows showing some support dialog on mobile devices.

Overall I can only agree with you that the bundle contains modules which are not required by the application. But excluding them without adding the risk of missing certain dependencies is quite a challenge and requires involvement from UI5 framework side as well. Therefore I'm labelling this issue as an enhancement rather than an issue.

matz3 avatar Jul 14 '21 07:07 matz3

@matz3 agreed, and thanks for the response. In our project, we consume multiple ui5 libraries as CDN preload bundles (library-preload.json files) and when looking at the code coverage, there is understandably quite a lot of code that is loaded yet never used during runtime.

However, when switching to the self-contained build, the resulting bundle size was hardly any smaller than the combined size of the preload bundles which the application would load earlier. For that reason, I started to have a look at the build result in the first place.

So it does seem to me that it would be important to make efforts from the UI5 framework side regarding how dependencies are being structured, so that the self-contained build could have much more of an impact on the bundle size.

BenReim avatar Jul 14 '21 12:07 BenReim