Skip to content

Commit 2130962

Browse files
authored
Merge pull request #2 from anbuarjun/master
Committed the treeshaking sample.
2 parents 8cfcaa4 + bf3f7b2 commit 2130962

11 files changed

Lines changed: 73 additions & 119 deletions

.github/workflows/gitleaks.yaml

Lines changed: 0 additions & 38 deletions
This file was deleted.

README.md

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,21 @@
11
# Tree Shaking in Angular
22

3-
Tree shaking in Angular eliminates unused modules from the final bundle file, reducing download size and improving performance. The Angular CLI uses Webpack, which supports tree shaking from version 2. Understanding tree shaking helps optimize application performance.
3+
The Angular CLI relies on the Webpack bundler to manage and bundle your application's code. Starting from version 2, Webpack introduced full-fledged support for tree shaking. As a result, when you build your Angular application using the Angular CLI, Webpack analyzes your codebase and automatically removes any unreachable or unused code segments.
44

5-
## Using Syncfusion Angular component with Tree Shaking
5+
## Using Syncfusion with Tree Shaking
66

7-
By default, Syncfusion Angular components supports Tree Shaking and it dose not require any special changes in application level.
7+
Syncfusion Angular components seamlessly support Tree Shaking by default, eliminating the need for any special modifications at the application level. Tree Shaking is a powerful technique that reduces the size of your application's bundle by removing unused code modules. This leads to faster load times and better overall performance.
88

99
## Implementing Tree Shaking in an Angular Application
1010

11-
Here are the steps for enabling Tree Shaking in an Angular application,
11+
Enabling Tree Shaking in your Angular application, especially when utilizing Syncfusion EJ2 Angular components, is a straightforward process that can significantly enhance your application's efficiency.
1212

13-
1. Create an Angular application with Syncfusion EJ2 Angular components as described in the [Getting Started](../getting-started/angular-cli/) documentation using the [Angular CLI](https://cli.angular.io/).
13+
### Steps to Enable Tree Shaking
1414

15-
2. Run the `ng build --prod` or `ng serve --prod` command to build or serve the application with Tree Shaking enabled.
15+
Follow these steps to enable Tree Shaking in your Angular application,
1616

17-
A sample code snippet that shows how to enable Tree Shaking in the `angular.json` configuration file,
17+
1. Create an Angular Application with Syncfusion Components: Begin by setting up your Angular application with Syncfusion EJ2 Angular components. You can find detailed instructions on how to integrate Syncfusion components into your application in the [Getting Started](../getting-started/angular-cli/) documentation using the [Angular CLI](https://cli.angular.io/).
1818

19-
```json
19+
2. Build or Serve with Tree Shaking: Once your application is configured with Syncfusion components, you can enable Tree Shaking by building or serving the application with production settings. Run the `ng build --configuration=production` or `ng serve --configuration=production` command to build or serve the application with Tree Shaking enabled.
2020

21-
"configurations": {
22-
"production": {
23-
"optimization": true,
24-
"sourceMap": false,
25-
"namedChunks": false,
26-
"aot": true,
27-
"extractLicenses": true,
28-
"vendorChunk": false,
29-
"buildOptimizer": true
30-
}
31-
},
32-
33-
```
34-
35-
You can enhance the user experience and boost performance in your Angular application by following the steps above and implementing tree shaking.
21+
By adhering to these steps and integrating tree shaking into your Angular application, you can significantly enhance performance and elevate the user experience.

angular.json

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"version": 1,
44
"newProjectRoot": "projects",
55
"projects": {
6-
"ej2-angular-samples": {
6+
"syncfusion-angular-app": {
77
"projectType": "application",
88
"schematics": {},
99
"root": "",
@@ -13,7 +13,7 @@
1313
"build": {
1414
"builder": "@angular-devkit/build-angular:browser",
1515
"options": {
16-
"outputPath": "dist/ej2-angular-samples",
16+
"outputPath": "dist/syncfusion-angular-app",
1717
"index": "src/index.html",
1818
"main": "src/main.ts",
1919
"polyfills": [
@@ -25,7 +25,8 @@
2525
"src/assets"
2626
],
2727
"styles": [
28-
"src/styles.css"
28+
"src/styles.css",
29+
"./node_modules/@syncfusion/ej2-material-theme/styles/material.css"
2930
],
3031
"scripts": []
3132
},
@@ -41,8 +42,8 @@
4142
"budgets": [
4243
{
4344
"type": "initial",
44-
"maximumWarning": "500kb",
45-
"maximumError": "5mb"
45+
"maximumWarning": "6mb",
46+
"maximumError": "6mb"
4647
},
4748
{
4849
"type": "anyComponentStyle",
@@ -67,18 +68,18 @@
6768
"builder": "@angular-devkit/build-angular:dev-server",
6869
"configurations": {
6970
"production": {
70-
"browserTarget": "ej2-angular-samples:build:production"
71+
"browserTarget": "syncfusion-angular-app:build:production"
7172
},
7273
"development": {
73-
"browserTarget": "ej2-angular-samples:build:development"
74+
"browserTarget": "syncfusion-angular-app:build:development"
7475
}
7576
},
7677
"defaultConfiguration": "development"
7778
},
7879
"extract-i18n": {
7980
"builder": "@angular-devkit/build-angular:extract-i18n",
8081
"options": {
81-
"browserTarget": "ej2-angular-samples:build"
82+
"browserTarget": "syncfusion-angular-app:build"
8283
}
8384
},
8485
"test": {
@@ -94,12 +95,16 @@
9495
"src/assets"
9596
],
9697
"styles": [
97-
"src/styles.css"
98+
"src/styles.css",
99+
"./node_modules/@syncfusion/ej2-material-theme/styles/material.css"
98100
],
99101
"scripts": []
100102
}
101103
}
102104
}
103105
}
106+
},
107+
"cli": {
108+
"analytics": "ec65ef7b-4313-4c7f-9d42-d3587151da1b"
104109
}
105110
}

package.json

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,40 @@
11
{
2-
"name": "tree-shaking",
2+
"name": "syncfusion-angular-app",
33
"version": "0.0.0",
44
"scripts": {
55
"ng": "ng",
6-
"start": "ng serve --configuration=production",
7-
"build": "ng build --configuration=production",
6+
"start": "ng serve",
7+
"build": "ng build",
88
"watch": "ng build --watch --configuration development",
99
"test": "ng test"
1010
},
1111
"private": true,
1212
"dependencies": {
13-
"@angular/animations": "^15.1.0",
14-
"@angular/common": "^15.1.0",
15-
"@angular/compiler": "^15.1.0",
16-
"@angular/core": "^15.1.0",
17-
"@angular/forms": "^15.1.0",
18-
"@angular/platform-browser": "^15.1.0",
19-
"@angular/platform-browser-dynamic": "^15.1.0",
20-
"@angular/router": "^15.1.0",
21-
"@syncfusion/ej2-angular-grids": "*",
13+
"@angular/animations": "^16.2.0",
14+
"@angular/common": "^16.2.0",
15+
"@angular/compiler": "^16.2.0",
16+
"@angular/core": "^16.2.0",
17+
"@angular/forms": "^16.2.0",
18+
"@angular/platform-browser": "^16.2.0",
19+
"@angular/platform-browser-dynamic": "^16.2.0",
20+
"@angular/router": "^16.2.0",
21+
"@syncfusion/ej2-angular-grids": "^22.2.11",
2222
"rxjs": "~7.8.0",
2323
"tslib": "^2.3.0",
24-
"zone.js": "~0.12.0"
24+
"zone.js": "~0.13.0",
25+
"@syncfusion/ej2-material-theme": "~22.2.11"
2526
},
2627
"devDependencies": {
27-
"@angular-devkit/build-angular": "^15.1.4",
28-
"@angular/cli": "~15.1.4",
29-
"@angular/compiler-cli": "^15.1.0",
28+
"@angular-devkit/build-angular": "^16.2.1",
29+
"@angular/cli": "~16.2.1",
30+
"@angular/compiler-cli": "^16.2.0",
3031
"@types/jasmine": "~4.3.0",
31-
"jasmine-core": "~4.5.0",
32+
"jasmine-core": "~4.6.0",
3233
"karma": "~6.4.0",
33-
"karma-chrome-launcher": "~3.1.0",
34+
"karma-chrome-launcher": "~3.2.0",
3435
"karma-coverage": "~2.2.0",
3536
"karma-jasmine": "~5.1.0",
36-
"karma-jasmine-html-reporter": "~2.0.0",
37-
"typescript": "~4.9.4"
37+
"karma-jasmine-html-reporter": "~2.1.0",
38+
"typescript": "~5.1.3"
3839
}
39-
}
40+
}

src/app/app-routing.module.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { NgModule } from '@angular/core';
2+
import { RouterModule, Routes } from '@angular/router';
3+
4+
const routes: Routes = [];
5+
6+
@NgModule({
7+
imports: [RouterModule.forRoot(routes)],
8+
exports: [RouterModule]
9+
})
10+
export class AppRoutingModule { }

src/app/app.component.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,3 +481,4 @@ <h2>Next Steps</h2>
481481
<!-- * * * * * * * * * * End of Placeholder * * * * * * * * * * * -->
482482
<!-- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -->
483483

484+
<router-outlet></router-outlet>

src/app/app.component.spec.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,29 @@
11
import { TestBed } from '@angular/core/testing';
2+
import { RouterTestingModule } from '@angular/router/testing';
23
import { AppComponent } from './app.component';
34

45
describe('AppComponent', () => {
5-
beforeEach(async () => {
6-
await TestBed.configureTestingModule({
7-
declarations: [
8-
AppComponent
9-
],
10-
}).compileComponents();
11-
});
6+
beforeEach(() => TestBed.configureTestingModule({
7+
imports: [RouterTestingModule],
8+
declarations: [AppComponent]
9+
}));
1210

1311
it('should create the app', () => {
1412
const fixture = TestBed.createComponent(AppComponent);
1513
const app = fixture.componentInstance;
1614
expect(app).toBeTruthy();
1715
});
1816

19-
it(`should have as title 'tree-shaking'`, () => {
17+
it(`should have as title 'syncfusion-angular-app'`, () => {
2018
const fixture = TestBed.createComponent(AppComponent);
2119
const app = fixture.componentInstance;
22-
expect(app.title).toEqual('tree-shaking');
20+
expect(app.title).toEqual('syncfusion-angular-app');
2321
});
2422

2523
it('should render title', () => {
2624
const fixture = TestBed.createComponent(AppComponent);
2725
fixture.detectChanges();
2826
const compiled = fixture.nativeElement as HTMLElement;
29-
expect(compiled.querySelector('.content span')?.textContent).toContain('tree-shaking app is running!');
27+
expect(compiled.querySelector('.content span')?.textContent).toContain('syncfusion-angular-app app is running!');
3028
});
3129
});

src/app/app.component.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
1-
import { enableRipple } from '@syncfusion/ej2-base';
21
import { Component } from '@angular/core';
32

4-
// enable ripple effects
5-
enableRipple(true);
6-
73
@Component({
84
selector: 'app-root',
95
template: `
@@ -19,8 +15,8 @@ enableRipple(true);
1915
<e-column field='OrderDate' headerText='Order Date' textAlign='Right' format='yMd' width=120></e-column>
2016
</e-columns>
2117
</ejs-grid>
22-
`
23-
})
18+
`
19+
})
2420
export class AppComponent {
2521
public data: Object[] = [
2622
{

src/app/app.module.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
import { NgModule } from '@angular/core';
22
import { BrowserModule } from '@angular/platform-browser';
33

4+
import { AppRoutingModule } from './app-routing.module';
45
import { AppComponent } from './app.component';
5-
import { GridAllModule } from '@syncfusion/ej2-angular-grids';
6+
import { GridModule, PagerModule } from '@syncfusion/ej2-angular-grids';
67

78
@NgModule({
89
declarations: [
910
AppComponent
1011
],
1112
imports: [
12-
BrowserModule, GridAllModule
13+
BrowserModule,
14+
AppRoutingModule,
15+
GridModule, PagerModule
1316
],
1417
providers: [],
1518
bootstrap: [AppComponent]

src/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<html lang="en">
33
<head>
44
<meta charset="utf-8">
5-
<title>TreeShaking</title>
5+
<title>SyncfusionAngularApp</title>
66
<base href="/">
77
<meta name="viewport" content="width=device-width, initial-scale=1">
88
<link rel="icon" type="image/x-icon" href="favicon.ico">

0 commit comments

Comments
 (0)