DevExtreme Angular - Tree Shaking

Tree Shaking

The tree shaking mechanism removes unused portions of source and library code to reduce the downloaded size of the application.

The tree shaking mechanism checks whether you import only the modules used in your application. For instance, the following import takes the DxButtonModule from the devextreme-angular module:

TypeScript
import { DxButtonModule } from 'devextreme-angular';

If tree shaking is not configured in your application, import exports from specific modules instead of the main devextreme-angular module to reduce the bundle size:

TypeScript
import { DxButtonModule } from 'devextreme-angular/ui/button';
NOTE
The tree shaking mechanism works only when you create the production bundle.

Bundle Size

DevExtreme code consists of three main code groups: - Utilities Code An application imports Utilities Code, when you add a DevExtreme component. Utilities Code is mandatory for DevExtreme components and the tree shaking mechanim does not remove this code.

  • Data Visualization Components Code The bundle includes the Data Visualization components code if you use the Chart component in your application. The Data Visualization components code has a large file size and may affect the resulting bundle.

  • UI Components Code The size of the UI Components Code depends on components that you use in your application. For example, you can import a simple component (such as Button) and the resulting bundle will contain only this component code. Complex components (such as DataGrid, Scheduler, or PivotGrid) include multiple simple components. If you import DataGrid to your application, the bundle includes code of the ScrollView, Button, TextBox, Form, and other components .

To summarize, the tree shaking mechanism does not affect the resulting bundle if you use a complex UI and Data Visualization in the application. However, if you use simple components, the tree shaking mechanism will remove unnecessary code from the production bundle. Refer to the following Github issue for more details about bundle size in DevExtreme Angular applications: Large Bundle Size - Angular.

The table below contains information about the size of common modules after you import them to the application:

Module Raw Size Transfer Size
Empty App 216.09 kB 60.11 kB
DxDataGridModule 2.01 MB 456.46 kB
DxButtonModule 490.44 kB 122.62 kB
DxTextBoxModule 688.89 kB 162.69 kB
DxFormModule 1.11 MB 249.49 kB
DxChartModule 1.10 MB 283.46 kB
DxVectorMapModule 820.20 kB 209.38 kB
DxSelectBoxModule 977.27 kB 218.51 kB
DxSchedulerModule 2.00 MB 389.43 kB