You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
bug: All ionic components are bundled, even unused components #25212
I have searched for existing issues that already report this problem, without success.
Ionic Framework Version
v4.x
v5.x
v6.x
Nightly
Current Behavior
Hello,
I'm currently using Vite with ionic react, and when building the app a large chunk file with some small ones, will be created.
when I used rollup-plugin-visualizer I realized that all ionic components are bundled.
Expected Behavior
should be tree-shakable
Steps to Reproduce
just build with Vite.
I also tried with default webpack version and result is same.
Are you able to provide a minimal reproduction of the issue? It's hard to verify if this is an Ionic bug when I have to go through a lot of your app's business logic. For example, the Telegram.tsx file is quite large. If that is not needed to reproduce the issue, I recommend removing it from the sample app.
I do not recommend using bundle analyzer tools as the basis for analyzing treeshaking. They typically show what the bundler has processed, not necessarily what the final build result is after treeshaking. For example, we had a similar issue in #25005 but the issue ended up being that the bundle analyzer was not showing the treeshaking results.
What results do you get when you run npm run build using only the code provided in #25212 (comment)?
I've got same results with 265kb index bundle.
I also removed IonApp and result was about 140kb index file...
Sems like IonApp component itself, is 120kb bundled.
If this size is normal for this component, then every thing is OK.
IonApp has a few dependencies needed to bootstrap Ionic, so IonApp itself likely is not 120KB.
For example, the JS files you see that are in the single digit KBs are utilities that all Ionic apps need.
The swiper.bundle.js file really should not be there, but this is unavoidable due to how we bundle the compiled Swiper library. The good news is ion-slides, the component that uses swiper.bundle.js, is deprecated and scheduled for removal in Ionic 7. Once that release ships, this issue should be resolved automatically.
The remaining file size is primarily comprised of a few things:
The IonApp component itself.
Several global stylesheets that get loaded.
The Stencil runtime.
I do see several components getting bundled that are not being used in your app. However, most of these are components that almost all apps are going to use. For example, code for ion-ripple-effect is in the bundle. This is used in several components including IonTabButton, IonButton, and IonItem.
While there are likely some improvements we can make to how "treeshakable" Ionic is, I am not seeing every Ionic component getting bundled. We are tracking some treeshaking improvements internally and are looking to roll those improvements out in upcoming releases of Ionic.
Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Ionic, please create a new issue and ensure the template is fully filled out.
Activity
liamdebeasi commentedon Apr 28, 2022
Thanks for the issue. Can you please provide a GitHub repo I can use to verify this behavior?
arasrezaei commentedon Apr 30, 2022
sure:
https://github.com/arasrezaei/mocholmag
liamdebeasi commentedon May 2, 2022
Are you able to provide a minimal reproduction of the issue? It's hard to verify if this is an Ionic bug when I have to go through a lot of your app's business logic. For example, the
Telegram.tsxfile is quite large. If that is not needed to reproduce the issue, I recommend removing it from the sample app.arasrezaei commentedon May 2, 2022
I can confirm that even by importing only IonApp component all components are bundled:


liamdebeasi commentedon May 2, 2022
When I run a production build using just that code I get the following:
I do not recommend using bundle analyzer tools as the basis for analyzing treeshaking. They typically show what the bundler has processed, not necessarily what the final build result is after treeshaking. For example, we had a similar issue in #25005 but the issue ended up being that the bundle analyzer was not showing the treeshaking results.
What results do you get when you run
npm run buildusing only the code provided in #25212 (comment)?arasrezaei commentedon May 2, 2022
I've got same results with 265kb index bundle.
I also removed IonApp and result was about 140kb index file...
Sems like IonApp component itself, is 120kb bundled.
If this size is normal for this component, then every thing is OK.
liamdebeasi commentedon May 2, 2022
IonApphas a few dependencies needed to bootstrap Ionic, so IonApp itself likely is not 120KB.For example, the JS files you see that are in the single digit KBs are utilities that all Ionic apps need.
The
swiper.bundle.jsfile really should not be there, but this is unavoidable due to how we bundle the compiled Swiper library. The good news ision-slides, the component that usesswiper.bundle.js, is deprecated and scheduled for removal in Ionic 7. Once that release ships, this issue should be resolved automatically.The remaining file size is primarily comprised of a few things:
I do see several components getting bundled that are not being used in your app. However, most of these are components that almost all apps are going to use. For example, code for
ion-ripple-effectis in the bundle. This is used in several components including IonTabButton, IonButton, and IonItem.While there are likely some improvements we can make to how "treeshakable" Ionic is, I am not seeing every Ionic component getting bundled. We are tracking some treeshaking improvements internally and are looking to roll those improvements out in upcoming releases of Ionic.
I am going to close this issue for now. Thanks!
ionitron-bot commentedon Jun 1, 2022
Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Ionic, please create a new issue and ensure the template is fully filled out.