timmaffett / material_symbols_icons

Complete Flutter support for google's Material DesignMaterial Symbols Icons
Apache License 2.0
32 stars 5 forks source link

Tree shaking #7

Closed xVemu closed 10 months ago

xVemu commented 10 months ago

Does this package support tree shaking?

timmaffett commented 10 months ago

Yes this package supports tree shaking. In order to do this I had to make it work with a limitation of flutter tree shaking however, and that is that one icon is included from each of the style variations. This happens automatically so there is nothing you have to do to make this happen. The icon included from each style (outline, rounded and sharp) is the smallest icon and it is around 400 bytes. So including this package and using no icons results in about 1200 bytes after tree shaking. During the build process the tree shaking will be reported to you and you can see the exact amount that you are using for your project.

juriejan commented 6 months ago

I'm using the latest version of Flutter (3.16.0) and this package (4.2711.0) and only displaying one icon, but it seems that my tree shaking isn't working as expected.

Font asset "MaterialIcons-Regular.otf" was tree-shaken, reducing it from 1645184 to 8164 bytes (99.5% reduction). Tree-shaking can be disabled by providing the --no-tree-shake-icons flag when building your app.
Font asset "MaterialSymbolsOutlined[FILL,GRAD,opsz,wght].ttf" was tree-shaken, reducing it from 8252008 to 8061636 bytes (2.3% reduction). Tree-shaking can be disabled by providing the --no-tree-shake-icons flag when building your app.
Font asset "MaterialSymbolsSharp[FILL,GRAD,opsz,wght].ttf" was tree-shaken, reducing it from 6845152 to 6654780 bytes (2.8% reduction). Tree-shaking can be disabled by providing the --no-tree-shake-icons flag when building your app.
Font asset "MaterialSymbolsRounded[FILL,GRAD,opsz,wght].ttf" was tree-shaken, reducing it from 11431196 to 11240824 bytes (1.7% reduction). Tree-shaking can be disabled by providing the --no-tree-shake-icons flag when building your app.

Thanks for making this package!

timmaffett commented 5 months ago

@juriejan Tree shaking of the Material Symbols Icons should work (and does working for me in a variety of projects where I use them). Are you sure there is not a reference to all of the material symbols (such as I do in example\lib\symbols_map.dart within the example app of the package) ? Otherwise if you could provide an example I can look into the problem you are seeing further.