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: bundle size larger than expected with ionic 6 + webpack #25005
I have searched for existing issues that already report this problem, without success.
Ionic Framework Version
v4.x
v5.x
v6.x
Current Behavior
This is a follow-up to #24280, which was closed as fixed. Unfortunately, I am still having the same issue-- in Ionic 5, with a React app, the first big chunk of my app was about 500 Kb, but with Ionic 6, it's 1.4 MB.
I also tried using the tool's "show bundle content (inaccurate) option:
What surprised me about the above result is that it shows that ion-slides, ion-accordion-group, ion-breadcrumb, and other components that I do not use in my app are being pulled in, so this is likely the source of the bloat.
Expected Behavior
I expected Ionic 5 and 6 to be roughly the same size.
Steps to Reproduce
Update a moderately sized app from v5 to v6. I am using CRA5 with Webpack 5.
I set "@ionic/core": "6.0.14-dev.11648082573.18baa25a", in package.json, ran npm up, and rebuilt my app; unfortunately, I still see basically the same size (1.37 MB).
I deleted the build directory to ensure I wasn't getting something cached, and I also double-checked package-lock.json to ensure @ionic/core got updated. Did I mess a step somewhere?
@ptmkenny you will need to update the @ionic/react package version and remove any specific @ionic/core version, as it will pull in the correct version for the dev build:
"@ionic/react": "6.0.14-dev.11648082573.18baa25a"
The offending code for the treeshaking issue was an import to the hydrated bundle in @ionic/react.
@sean-perkins Thanks for the guidance. Unfortunately, I'm still getting almost the same size (1.25 MB).
It seems that all Ionic components are getting included for some reason. To demonstrate this, I created a new repo with my package.json and only index.tsx and App.tsx; when I run react-scripts build --stats; webpack-bundle-analyzer build/bundle-stats.json, I get a bloated build.
Actually, digging into this further, perhaps including things like accordion in core/components is the expected behavior?
I did some more testing with my actual app (not the repro repo) and found the following:
Upgrading from Ionic 5 to 6, the size of the largest bundle increases significantly (more than doubles).
Updating from Ionic 6 current release to the bugfix release, the largest bundle size stays the same, but the overall size of the app goes down significantly.
Largest individual bundle size vs. total app size
Ionic 5: 677 kB / 2.79 MB
Ionic 6 current: 1.37 MB / 3.89 MB
Ionic 6 bugfix: 1.28 MB / 2.68 MB
Could you please confirm this is the expected behavior? The overall bundle in 6 being smaller than 5 is great, but I'm a little worried that the much bigger initial bundle will slow down app load times.
I took a look at your reproduction, and I think webpack-bundle-analzyer may be misrepresenting the results.
When looking at webpack-bundle-analyzer it reports that ion-picker.js was processed. However, the source code for ion-picker.js was not actually found in the build directory for your app. I noticed in the screenshots that you have "Show contents of concatenated modules" enabled. This feature can yield inaccurate results, and I do not recommend using it as the basis for treeshaking analysis.
To test the true treeshaken bundle size, I looked at the total file size of all the non-source map JS files in build/static:
v6.0.13
v6.0.14
total JS size
1.8mb
507kb
largest chunk
457kb
367kb
Can you try your build again and see if you can find any un-used Ionic modules imported in the build directory? I typically look in the main.*.js file. There will be a few Ionic utilities that are included in your bundle that you did not explicitly import. Those are dependencies of IonApp.
@liamdebeasi Ok thanks. I had some more time to look at this and I see that the actual bundles are correct, and the webpack-bundle-analyzer output is inaccurate.
I'll close this now as the issue is completely solved in the latest release. Many thanks for such a thorough solution!
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
sean-perkins commentedon Mar 28, 2022
@ptmkenny thanks for reporting this issue.
While the PR for #24280 did partially improve the treeshaking behavior, the root issue was resolved in this recent PR: #24989.
You can validate for yourself with this dev build:
Here is an example comparison with the blank Ionic react starter:
v6.0.13 stats:
dev build stats:
Can you validate on your end and let me know if the build is still bloated?
ptmkenny commentedon Mar 29, 2022
@sean-perkins Thank you for the response.
I set
"@ionic/core": "6.0.14-dev.11648082573.18baa25a",inpackage.json, rannpm up, and rebuilt my app; unfortunately, I still see basically the same size (1.37 MB).I deleted the
builddirectory to ensure I wasn't getting something cached, and I also double-checkedpackage-lock.jsonto ensure@ionic/coregot updated. Did I mess a step somewhere?sean-perkins commentedon Mar 29, 2022
@ptmkenny you will need to update the
@ionic/reactpackage version and remove any specific@ionic/coreversion, as it will pull in the correct version for the dev build:The offending code for the treeshaking issue was an import to the hydrated bundle in
@ionic/react.ptmkenny commentedon Mar 30, 2022
@sean-perkins Thanks for the guidance. Unfortunately, I'm still getting almost the same size (1.25 MB).
It seems that all Ionic components are getting included for some reason. To demonstrate this, I created a new repo with my
package.jsonand onlyindex.tsxandApp.tsx; when I runreact-scripts build --stats; webpack-bundle-analyzer build/bundle-stats.json, I get a bloated build.The repo to demonstrate this is available here: https://github.com/ptmkenny/ionic-react-bloat
ptmkenny commentedon Mar 30, 2022
Actually, digging into this further, perhaps including things like
accordionincore/componentsis the expected behavior?I did some more testing with my actual app (not the repro repo) and found the following:
Largest individual bundle size vs. total app size
Could you please confirm this is the expected behavior? The overall bundle in 6 being smaller than 5 is great, but I'm a little worried that the much bigger initial bundle will slow down app load times.
Screenshots below.
Ionic 5 (CKEditor hidden):
Ionic 6 current release (CKEditor hidden):
Ionic 6 bugfix release (CKEditor hidden):
liamdebeasi commentedon Mar 30, 2022
Hey @ptmkenny,
There was indeed a treeshaking issue that @sean-perkins did a great job fixing. This fix is available now in Ionic 6.0.14. I observed a bundle size reduction in https://github.com/ptmkenny/ionic-react-bloat after building with v6.0.14.
I took a look at your reproduction, and I think
webpack-bundle-analzyermay be misrepresenting the results.When looking at
webpack-bundle-analyzerit reports thation-picker.jswas processed. However, the source code forion-picker.jswas not actually found in thebuilddirectory for your app. I noticed in the screenshots that you have "Show contents of concatenated modules" enabled. This feature can yield inaccurate results, and I do not recommend using it as the basis for treeshaking analysis.To test the true treeshaken bundle size, I looked at the total file size of all the non-source map JS files in
build/static:Can you try your build again and see if you can find any un-used Ionic modules imported in the
builddirectory? I typically look in themain.*.jsfile. There will be a few Ionic utilities that are included in your bundle that you did not explicitly import. Those are dependencies of IonApp.ptmkenny commentedon Apr 4, 2022
@liamdebeasi Ok thanks. I had some more time to look at this and I see that the actual bundles are correct, and the
webpack-bundle-analyzeroutput is inaccurate.I'll close this now as the issue is completely solved in the latest release. Many thanks for such a thorough solution!
ionitron-bot commentedon May 4, 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.