question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Tree Shaking not reducing the overall package size of an Angular application

See original GitHub issue

Hi,

We compared using ngx-echarts with full echarts against echarts tree shakable API’s. For experimenting we used the demo sample given @https://github.com/xieziyu/ngx-echarts-starter

Option 1: Full ECharts imported

@NgModule({
  imports: [
    NgxEchartsModule.forRoot({
      /**
       * This will import all modules from echarts.
       * If you only need custom modules,
       * please refer to [Custom Build] section.
       */
      echarts: () => import('echarts'), // or import('./path-to-my-custom-echarts')
    }),
  ],
})

Our observation is this: image

Total Main.js Size: 1.1 MB; Total Network transfer: 1.2MB

Option 2: Using tree shakable API’s from ECharts

import * as echarts from 'echarts/core';
import { LineChart } from 'echarts/charts';
import {
  TitleComponent,
  TooltipComponent,
  GridComponent
} from 'echarts/components';
// Import the Canvas renderer, note that introducing the CanvasRenderer or SVGRenderer is a required step
import {
  CanvasRenderer
} from 'echarts/renderers';
import 'echarts/theme/macarons.js';

echarts.use(
  [TitleComponent, TooltipComponent, GridComponent, LineChart, CanvasRenderer]
);

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    NgxEchartsModule.forRoot({ echarts }),
    HttpClientModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})

Our observation is, image Total Main.js Size: 1.2 MB; Total Network transfer: 1.2MB

So as you could see total size of main.js increased with tree shakable API usage. What could be the reason for the increase in package size after using tree shakable API?

Please let us know in case the approach we followed is not correct.

Thanks Basanth

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
msbasanthcommented, Jun 21, 2021

I tried the suggestion from echarts contributor and looks like tree shaking is working in echarts. 👍 https://github.com/apache/echarts/issues/15138

But the same approach of registering the theme ourselves by passing json (basically avoiding require(‘echarts’)) didn’t work here with ngx-echarts.

This is what I tried, instead of importing style directly I registered theme manually.

import * as echarts from 'echarts/core';
echarts.registerTheme('dark', { <<Entire theme as json>>});

Even with this network transfer shows same size 1.2MB for the application.

0reactions
tymfearcommented, Feb 22, 2022

@xieziyu from this issue I didn’t really get how to tree shake echarts in Angular. Could you provide some examples and/or explanations other than in linked issues?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Reduce the Bundle Size of Your Angular App | Pluralsight
In this guide, you learned three strategies for reducing the production bundle size of your Angular app. First, you learned both how to...
Read more >
Dev Discussions: How to Reduce your Angular Bundle Size ...
Bundle reduction tip #1: Use tree shaking​​ This presents a problem in that importing the entire library can drastically increase your bundle  ......
Read more >
Honey, I shrunk the bundle — A story about Angular ... - Medium
One main problem we were facing was the bundle size and the overall performance of the application in the browser. It felt non-responsive...
Read more >
Angular - How to improve bundle size? - Daniel Kreider
Is your Angular application slow? Here are 5 ways you can reduce the bundle size. And make it load faster. · 1. Investigate...
Read more >
How to decrease prod bundle size? - angular - Stack Overflow
This is not out of the norm for angular2 applications, even if you are using ... AOT & Tree Shaking (angular-cli does this...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found